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>