自定义ArrayAdapter上的可单击行

问题描述

|| 我为ListView制作了一个自定义ArrayAdapter,以便使用某些元素来自定义列表的行。 我的问题是我无法选择一个项目,单击时什么也没有发生。我必须在自定义ArrayAdapter中实现它吗?它只有一个构造函数一个getView方法。当我实例化列表并实现onListItemClick时,它将被忽略,因此我认为这与我的自定义适配器有关……我通过示例进行了研究,但没有发现任何问题。 我该怎么办? 编辑:在每一行中,我都使用一个复选框和一个包含TextViews的LinearLayout。该LinearLayout是应该可选的。     

解决方法

我认为问题是Android不允许您选择列表元素上具有可聚焦元素的列表项。 将您在lisview中的复选框设置为“不可聚焦”。 请参阅此以获取详细信息:
android:focusable=\"false\"
Android自定义ListView无法单击项目
<checkbox>.setFocusable(false)
http://groups.google.com/group/android-developers/browse_thread/thread/dc070331341ef34/fa6d4356118a1f0d?lnk=gst&q=button+listview+clicks#fa6d4356118a1f0d     ,我整天都在努力解决这个问题!这是您的listitem的layout / xml外观: 此行应该在所有TextViews和您正在使用的其他组件上:
android:focusable=\"false\"
android:clickable=\"false\"/> 
我的listitem的layout.xml:
    <?xml version=\"1.0\" encoding=\"utf-8\"?>
    <LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
    android:layout_width=\"fill_parent\" 
    android:layout_height=\"fill_parent\">    

    <LinearLayout
    android:orientation=\"vertical\"
    android:layout_width=\"0dip\" 
    android:layout_weight=\"1\"
    android:layout_height=\"fill_parent\">

        <TextView
        android:layout_width=\"fill_parent\"
        android:layout_height=\"wrap_content\"
        android:id=\"@+id/textWhiteTheme\" 
        style=\"@style/list_item_wh\"
        android:focusable=\"false\"
        android:clickable=\"false\"/>        

    </LinearLayout>
</LinearLayout>