所以我ExpandableListView
具有被定義如下組行:獲取的PopupMenu的情況下像文本菜單
group_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/GroupName"
style="@style/ListViewRowStyle"
android:paddingLeft="40dp"
android:textSize="18sp" >
</TextView>
<ImageView
android:id="@+id/Menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:contentDescription="@string/default_content_description_text"
android:src="@drawable/ic_menu_moreoverflow_normal_holo_light" >
</ImageView>
</RelativeLayout>
當你點擊TextView
將取決於是否展開或摺疊或者不是當前顯示子行。我已將OnClickListener
附加到組行中的ImageView
。當這個ImageView
點擊我發動PopupMenu
像下面的圖片:
一旦PopupMenu
顯示和動作中的一個被點擊,我想執行的所有動作小組的孩子。問題是我無法確定點擊了哪一行。
我想通了如何將一個動作適用於所有孩子的唯一方法是用ContextMenu
像下面的圖片:
我想避免使用ContextMenu
,因爲上一組LongClick對於用戶來說行可能並不明顯,它會引起一些行爲在子行上執行。我認爲更明顯的設計是將PopupMenu
錨定到ImageView
(在我的情況下是菜單圖標),並將該操作應用於該組的子行。如何通過PopupMenu
獲得此功能?
儘管它已經過,因爲你張貼這一年,我不同的解決了這一點,並使用contextView保持,但如果附着的觀點相匹配的某個ID我想將其轉換彈出。 http://stackoverflow.com/questions/12407722/how-to-cancel-the-creation-of-a-context-menu-after-oncreatecontextmenu-has-bee/24014727#24014727 如果你在這裏檢查我的答案'感興趣。 (讓我知道如果我是一個白癡) –