Android 上下文菜单不支持';行布局中有开关时不能工作
我的片段中有一个带有自定义适配器(从ArrayAdapter扩展而来)的ListView。 list.xml:Android 上下文菜单不支持';行布局中有开关时不能工作,android,android-contextmenu,Android,Android Contextmenu,我的片段中有一个带有自定义适配器(从ArrayAdapter扩展而来)的ListView。 list.xml: ... <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" /> ... 如果rowlayout中没有开关,则所有工作正常。但若它添加了,那个么当单击行时什么也并没有发生。 如
...
<ListView android:id="@android:id/list" android:layout_width="match_parent"
android:layout_height="match_parent" />
...
如果rowlayout中没有开关
,则所有工作正常。但若它添加了,那个么当单击行时什么也并没有发生。
如何解决此问题并同时使用上下文菜单和开关?添加
android:descendantFocusability="blocksDescendants"
到你的直线上
加
到您的文本视图
加
转到您的交换机谢谢!你帮了我这么多!
...
mListView = (AbsListView) view.findViewById(android.R.id.list); //my list
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(this);
registerForContextMenu(mListView); //set up context menu
...
android:descendantFocusability="blocksDescendants"
android:textIsSelectable="false"
android:focusable="false"