【问题标题】:Custom ListView item click event is not working自定义 ListView 项目单击事件不起作用
【发布时间】:2014-06-20 14:55:25
【问题描述】:

我的应用支持 ADA 合规性。为此我添加了

 android:focusable="true"

自定义ListView 项目的属性(3-4 个文本视图)。但在此之后我的ListView 项目点击事件不起作用。当我从列表项中删除上述属性时,它工作正常。但为了遵守 ADA,我需要这个。我该如何解决这个问题?

编辑:

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

【问题讨论】:

标签: android textview listviewitem onitemclicklistener


【解决方案1】:

在您的充气机布局的文本视图中添加:

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

在您的充气机的父布局中,即在充气机的相对布局中添加:

android:descendantFocusability="blocksDescendants" 

【讨论】:

    【解决方案2】:

    您可以从您的代码中删除上面的行并将android:clickable="false" 和android:focusable="false" 提供给您的所有文本视图,这样您的文本视图将没有焦点和点击,因此您的项目点击将起作用。

    【讨论】:

    • 但如果我删除 android:focusable="true" 我的应用将不支持 ADA。
    • 我已添加该标志以使我的应用程序符合 ADA 标准。如果有任何其他方法可以使其符合 ADA 标准,我已准备好删除此内容。否则不会。
    • 符合 ADA 标准,我没明白,你能解释一下吗?
    • ADA 代表美国残疾人法案。这意味着盲人应该能够使用我们的应用程序。在 IOS 中,有一种称为语音的功能。像这样,我必须让我的应用程序也对盲人有用。为此,应用程序中的每个组件都应该是可聚焦的并包含内容描述。
    • @seethalakshmi 好的,感谢您的解释。所以简而言之,你需要所有组件都应该是可聚焦的,对吧?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多