<< Android-Note
カスタムリストビュー内のフォーカスの分離
ListViewをカスタムして、例えばテキストビューの横にイメージボタンがついているようなアイテムを持つリストを作るとします。
そのとき、ボタンとリストビューのアイテムのどちらのフォーカスも受け取りたい場合はアイテムのトップビューのDescendantFocusabillityプロパティを"blocksDescendant"に設定します。
リストビューのアイテムのレイアウトファイルは次のようになります。
<?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" >
<!--descendantFocusibilityプロパティを変更-->
<TextView
android:id="@+id/list_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageButton
android:id="@+id/open_item_image_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/item_icon" />
</LinearLayout>
これでイメージボタンとリストビューのフォーカスを別々に受け取ることが可能になります。


© Kaz