我意识到关于这个问题有很多问题,但是将 row.xml 中的每个视图设置为 focusable="false" 和 focusableInTouchMode="false" 的解决方案不起作用,从 ListActivity 和设置中获取 ListView 也不起作用setItemsCanFocus(假)。
奇怪的是,当注册上下文菜单时,长按有效。常规水龙头呢?没有。我尝试设置像 OnItemClickListener 这样的监听器无济于事。
我在某处读到我可以通过在我的适配器中覆盖 getView() 来解决这个问题?我不太确定它是如何工作的。注意,我不想知道用户点击了哪个视图;我只关心单击列表行以启动 onListItemClick() 中的相应代码。
也许我的 row.xml 中有些东西全错了?或者它是否受到我设置 ListView 适配器的方式的影响(放置在 onResume() 而不是 onCreate() 以更新信息)?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:focusable="false"
android:focusableInTouchMode="false">
<TextView style="?android:attr/listSeparatorTextViewStyle"
android:id="@+id/listSectionHeader"
android:layout_width = "fill_parent"
android:layout_height="wrap_content"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:paddingLeft="5dp"
android:textColor="@android:color/white"
android:visibility="gone"
android:focusable="false"
android:focusableInTouchMode="false"/>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:background="@drawable/list_button"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="true"
android:longClickable="true"
>
<TextView android:id="@+id/itemID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:textStyle="bold"
android:layout_alignParentLeft="true"
android:focusable="false"
android:focusableInTouchMode="false"/>
<CheckBox
android:id="@+id/returnedCheckbox"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
/>
<LinearLayout
android:layout_toRightOf="@id/returnedCheckbox"
android:layout_margin="5dp"
android:layout_centerVertical="true"
android:orientation="vertical"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false">
<TextView
android:id="@+id/stuffName"
android:layout_width="fill_parent"
android:lines="1"
android:layout_height="wrap_content"
android:ellipsize="end"
android:scrollHorizontally="true"
android:text="Hey there"
android:textSize="25sp"
android:textColor="#FFF"
android:shadowColor="#000"
android:focusable="false"
android:focusableInTouchMode="false"
/>
<RelativeLayout
android:id="@+id/detailsLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false">
<TextView
android:id="@+id/dueListItem"
android:layout_width="wrap_content"
android:lines="1"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="@string/dueListing"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:id="@+id/dueDate"
android:layout_toRightOf="@id/dueListItem"
android:layout_marginLeft="2dp"
android:layout_width="90dp"
android:lines="1"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="HEHEHE"
android:focusable="false"
android:focusableInTouchMode="false"/>
<ImageView
android:id="@+id/starMark"
android:layout_alignRight="@id/detailsLayout"
android:layout_toRightOf="@id/dueDate"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:layout_height="15dp"
android:layout_width="15dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/list_starred"
android:visibility="invisible"
android:focusable="false"
android:focusableInTouchMode="false"/>
</RelativeLayout>
</LinearLayout>
<ImageView
android:id="@+id/contactPic"
android:layout_alignParentRight="true"
android:layout_height="48dp"
android:layout_width="48dp"
android:background="#FFF"
android:layout_margin="10dp"
android:layout_centerVertical="true"
android:scaleType="fitCenter"
android:padding="3dp"
android:focusable="false"
android:focusableInTouchMode="false"
/>
<ImageView
android:id="@+id/lentArrow"
android:visibility="invisible"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/indicator_lent"
android:layout_marginTop="42dp"
android:layout_marginRight="1dp"
android:focusable="false"
android:focusableInTouchMode="false"/>
</RelativeLayout>
</LinearLayout>