Android Listview OnItemClickListener 有时无法正常工作

标签 android listview onitemclicklistener

我有一个带有 ListView 的小型 Android 应用程序。有时 ListView 不会对我的输入使用react。我可以看到我触摸了一个项目(当我触摸它时它会改变颜色),但程序什么都不做。 这是我的 XML 文件:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="false"
    android:focusableInTouchMode="false" >

    <TextView
        android:id="@+id/textViewRowLable"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:textSize="50sp" />

    <TextView
        android:id="@+id/textViewTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@id/textViewRowLable"
        android:gravity="right"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/textViewRemainingTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@id/textViewTime"
        android:layout_toRightOf="@id/textViewRowLable"
        android:gravity="right"
        android:textSize="25sp" />

</RelativeLayout>

这是监听器:

 .setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) {
                        Toast.makeText(getApplicationContext(), "click", Toast.LENGTH_LONG).show();
                    }

                });

有人可以提示我为什么它并不总是有效吗?

谢谢

最佳答案

尝试在 RelativeLayout 上使用 android:descendantFocusability="blocksDescendants" 还要阅读本教程: Listview tips and tricks

关于Android Listview OnItemClickListener 有时无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24782752/

相关文章:

android - 如何更改 Lollipop 中的 DatePicker 日历 View 背景颜色?

java - 如何解决 java.util.zip.ZipException 重复条目 : com/google/gson/annotations/Expose. 类?

java - LisrView 子项的不同颜色

android - 无法在项目单击监听器上获取 gridView

android - 如何在数组的每次迭代后添加一些延迟,每次迭代都会更改 View 的属性。安卓

充当信标的 Android 设备

c# - ListView ItemActivate 延迟

android - 在对话框中使用 Drawable

android - 仅使用一行 listview 中的 imageview 来启动一个新的 intent

android - 单击按钮时在 map 上平移坐标 (Android)