简体   繁体   English

自定义ListView项目单击事件不起作用

[英]Custom ListView item click event is not working

My app is supporting ADA compliance. 我的应用程序支持ADA合规性。 For that I have added 为此,我添加了

 android:focusable="true"

property for custom ListView items (3-4 TextViews). 自定义ListView项的属性(3-4个TextViews)。 But after this my ListView item click event is not working. 但是在此之后,我的ListView项目单击事件不起作用。 When I removed above property from list items, it is working fine. 当我从列表项中删除以上属性时,它工作正常。 But for ADA compliance I need this. 但是为了符合ADA,我需要这样做。 How can I resolve this issue? 我该如何解决这个问题?

EDIT: 编辑:

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:nextFocusForward="@+id/city"
        android:text="****"
        android:focusable="true"
        android:textColor="@android:color/black"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/city"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:nextFocusForward="@+id/address"
        android:text="5145 N"
        android:focusable="true"
        android:textColor="@android:color/black" />

    <TextView
        android:id="@+id/address"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TX 78731"
        android:focusable="true"
        android:textColor="@android:color/black" />

</LinearLayout>

您可以从代码中删除上述行,并为所有textview提供android:clickable="false"android:focusable="false" ,这样您的textview将不会具有焦点和点击,因此可以进行项目点击。

in the textview of your inflator layout just add: 在充气机布局的文本视图中,只需添加:

android:focusable="false"
android:focusableInTouchMode="false"

and in parent layout of your inflator ie in relative layout of inflator add: 在充气机的父级布局中,即在充气机的相对布局中添加:

android:descendantFocusability="blocksDescendants" 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM