Android:上下文菜单没有显示ListView,其成员由LinearLayout定义?

Ran*_*ngy 3 java android listview

我有一个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"/>
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试更复杂的东西时,比如显示名称和CheckBox,菜单永远不会出现:

<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>
Run Code Online (Sandbox Code Playgroud)

长按可以处理更复杂的元素吗?我正在建立2.1.

(编辑)

在ListActivity上注册:

registerForContextMenu(getListView());
Run Code Online (Sandbox Code Playgroud)

我发布的代码是列表的项目模板.

Com*_*are 7

CheckBox可能在干涉事情.考虑使用a CheckedTextView而不是a LinearLayout,CheckBoxTextView组合,因为CheckedTextViewAndroid是CHOICE_MODE_MULTIPLE列表所期望的.

退房$ANDROID_HOME/platforms/$VERSION/data/res/layout/simple_list_item_multiple_choice.xml,$ANDROID_HOME无论你在哪里安装SDK,$VERSION都是一些Android版本(例如android-2.1).此资源是您应该用于CHOICE_MODE_MULTIPLE列表的标准资源.您可以随意将其复制到项目中,并CheckedTextView根据需要调整样式.