Android Listview项目不接受单击
我有这样的布局:Android Listview项目不接受单击,android,android-layout,android-listview,Android,Android Layout,Android Listview,我有这样的布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:descendantFocusability="b
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textViewId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textViewText"
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:singleLine="false"
android:layout_weight="1" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonOk"
android:clickable="true"
android:focusable="false"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
我有一个自定义适配器和一个视窗夹。但listview项目不可单击。目前,我仍然没有任何按钮本身的代码。我想能够点击整个listview项目了
上面的方法不是正确的吗?在ListView中,使用setOnItemClickListener
这是处理ListView上单击事件的最简单方法是否使用自定义适配器?@Lady_ari是。对于ViewHolder,我建议尝试在父级
RelativeLayout
上设置一个onClickListener
,看看这个:在ListFragment或ViewHolder上?使用ListFragment试试
@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
MyItem item = items.get(position);
//Do something...
}