Skip to content Skip to sidebar Skip to footer

Inflate Popup Menu Items Programmatically

I have a button in my activity, pressing upon which, the following method gets called - private ArrayList myListViewList; private ArrayList myA

Solution 1:

Check this code for Pop-up window

LayoutInflaterinflater= (LayoutInflater) PopupMain.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 finalViewlayout= inflater.inflate(R.layout.popup,        
 (ViewGroup)findViewById(R.id.popup_menu_root));
 PopupWindowpw=newPopupWindow(layout, 300,100, true);
 pw.dismiss();
 pw.showAtLocation(layout, Gravity.BOTTOM, 0, 10);

And your New pop-up layout should be as follows :

Popup.xml :

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/popup_menu_root"android:background="#FFFFFF"android:orientation="vertical"android:layout_width="wrap_content"android:layout_height="20dip" ><TextViewandroid:id="@+id/popup_menu_button1"android:text="Copy"android:textColor="#000000"android:layout_width="fill_parent"android:layout_height="wrap_content" /></LinearLayout>

This line decide the Height and width of your New View(Pop up window)

PopupWindowpw=newPopupWindow(layout, 300,100, true);

and pw.showAtLocation(layout, Gravity.BOTTOM, 0, 10);

tells where the Pop-up window should displays..

Post a Comment for "Inflate Popup Menu Items Programmatically"