java ListView项目不可点击(事件焦点=false)
我有一个包含imageview、textview和复选框的列表视图。当我添加imageview时,这些行变得不可读取。我已经尝试了很多解决方案,包括安卓:focusable="false"
、安卓:descendantFocusability="blocksDescendants"
和安卓:clickable=true
以下是我的列表视图:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:background="#000000"
安卓:clickable="true"
安卓:descendantFocusability="blocksDescendants"
安卓:orientation="vertical" >
<ImageView
安卓:id="@+id/imgListView"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_alignParentLeft="true"
安卓:layout_centerVertical="true"
安卓:focusable="false"
安卓:src="@drawable/ic_launcher" />
<TextView
安卓:id="@+id/txtListView"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_centerVertical="true"
安卓:layout_toRightOf="@id/imgListView"
安卓:focusable="false"
安卓:textColor="#FFFFFF" />
<CheckBox
安卓:id="@+id/chkListView"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_alignParentRight="true"
安卓:layout_centerVertical="true"
安卓:focusable="false" />
</RelativeLayout>
下面是使用它的活动:
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:background="#000000"
安卓:paddingBottom="@dimen/activity_vertical_margin"
安卓:paddingLeft="@dimen/activity_horizontal_margin"
安卓:paddingRight="@dimen/activity_horizontal_margin"
安卓:paddingTop="@dimen/activity_vertical_margin"
tools:context=".FolderActivity" >
<ListView
安卓:id="@+id/lstFolders"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:layout_alignParentLeft="true"
安卓:layout_alignParentTop="true"
安卓:dividerHeight="1dp"
安卓:divider="#FFFFFF">
</ListView>
</RelativeLayout>
我只需要像以前一样再次单击这些行
PS:当我第一次添加复选框并用^{
# 1 楼答案
为什么不在适配器的getview方法中为这些视图中的每一个编写单击侦听器呢。 另请参考此问题
Android: ListView elements with multiple clickable buttons
就连我也遇到过同样的问题,根据我的经验,如果在listview中只有一个元素是可点击的,那么xml参数就可以工作,对于多个元素,我只在适配器中编写了它
# 2 楼答案
我们需要进行以下更改,以避免单击/关注listview项的组件,从而允许在listview上单击项