我有一个ListActivity和ListView,并将一些数据绑定到它上面。数据显示正常,我还为视图注册了上下文菜单。当我将列表项仅显示为简单的TextView时,它可以正常工作:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nametext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
然而,当我尝试一些更复杂的操作,例如显示名称和复选框时,菜单从未显示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="@+id/nametext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<CheckBox
android:id="@+id/namecheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
长按操作是否适用于更复杂的元素?我正在使用2.1版本进行构建。
(编辑)
在ListActivity中注册以下内容:
registerForContextMenu(getListView());
我发布的代码是列表的项目模板。
ListView
上使用setItemChecked()
。 - CommonsWare