我在活动中,pressing按钮赖以,下面的方法被调用 -
I have a button in my activity, pressing upon which, the following method gets called -
private ArrayList<ListView> myListViewList; private ArrayList<MyListAdapter> myAdapterList; public void onPopupButtonClick(View button) { Log.v(TAG, "onPopupButtonClick"); PopupMenu popup = new PopupMenu(this, button); Menu menu = popup.getMenu(); // how do i display the myListViewList as items of in this popup menu // i.e how do i inflate myListViewList into menu object? }我知道如何为活动做编程方式 - 创建的活动的上下文linearlayouts和列表视图,最后用addContentView
I know how to do this programatically for an activity - creating linearlayouts and listViews and finally using addContentView on the activity's context.
但找到如上所述很难做同样的弹出式菜单中的场景。
But finding it hard to do the same for the popup menu scenario as described above.
任何帮助是极大AP preciated。
Any help is greatly appreciated.
TIA。
推荐答案勾选此code的弹出式窗口
Check this code for Pop-up window
LayoutInflater inflater = (LayoutInflater) PopupMain.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View layout = inflater.inflate(R.layout.popup, (ViewGroup)findViewById(R.id.popup_menu_root)); PopupWindow pw = new PopupWindow(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:
Popup.xml :
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="schemas.android/apk/res/android" android:id="@+id/popup_menu_root" android:background="#FFFFFF" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="20dip" > <TextView android: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)
PopupWindow pw = new PopupWindow(layout, 300,100, true);和 pw.showAtLocation(布局,Gravity.BOTTOM,0,10);
告诉那里的弹出窗口显示应该..
tells where the Pop-up window should displays..
更多推荐
充气弹出菜单项编程
发布评论