安卓:上下文菜单不露面与LinearLayout中定义的成员的ListView? [英] Android: Context menu doesn't show up for ListView with members defined by LinearLayout?

查看:155
本文介绍了安卓:上下文菜单不露面与LinearLayout中定义的成员的ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListActivity和ListView,我已经绑定了一些数据给它。数据显示细了,我也注册了一个上下文菜单视图。当我显示列表项只是一个简单的TextView,它工作正常:

I've got a ListActivity and ListView and I've bound some data to it. The data shows up fine, and I've also registered a context menu for the view. When I display the list items as just a simple TextView, it works fine:

<TextView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/nametext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

然而,当我尝试一些更复杂,如节目的名字和一个CheckBox,菜单一直没有出现:

However when I try something a bit more complex, like show the name and a CheckBox, the menu never shows up:

<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>

能否长期presses上更复杂的元素工作?我建立在2.1。

Can long-presses work on more complex elements? I'm building on 2.1.

(编辑)

本上ListActivity注册:

Registering with this on the ListActivity:

registerForContextMenu(getListView());

在code我贴是列表中的项目模板。

The code I posted is the item template for the list.

推荐答案

复选框可以与干扰的问题。考虑使用的 CheckedTextView 代替的LinearLayout 复选框,和的TextView 组合,因为 CheckedTextView 是Android的预期为 CHOICE_MODE_MULTIPLE 列表。

Your CheckBox may be interfering with matters. Consider using a CheckedTextView instead of a LinearLayout, CheckBox, and TextView combination, since CheckedTextView is what Android expects for a CHOICE_MODE_MULTIPLE list.

看看 $ ANDROID_HOME /平台/ $ VERSION /数据/ RES /布局/ simple_list_item_multiple_choice.xml ,其中 $ ANDROID_HOME 是无论你安装SDK和 $版本一些Android版本(例如, Android的2.1 )。这种资源是你应该为 CHOICE_MODE_MULTIPLE 列表使用标准资源。随意将它复制到你的项目和调整的造型的 CheckedTextView 需要。

Check out $ANDROID_HOME/platforms/$VERSION/data/res/layout/simple_list_item_multiple_choice.xml, where $ANDROID_HOME is wherever you installed the SDK and $VERSION is some Android version (e.g., android-2.1). This resource is the standard resource you should use for CHOICE_MODE_MULTIPLE lists. Feel free to copy it into your project and adjust the styling of the CheckedTextView as needed.

这篇关于安卓:上下文菜单不露面与LinearLayout中定义的成员的ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆