我有一个带有 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/