Listview通用问题,包括窜选啊、抢占焦点,抢占焦点的解决方案如下:
方案一:
给抢占焦点的控件设置属性
android:focusable="false"
方案二:
给Listview的item的根容器设置如下属性:
android:descendantFocusability="blocksDescendants"
example
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:focusable="false"
android:text="确定" />
</LinearLayout>