リストビューを表示し、そのリストビューに対してクリックイベントをつけていたのですが、機能を拡張しようと思い、リストビューの行ごとにイメージボタンを付けたら。今までの動いていたリストビューのクリックイベントが反応しなくなりました。。
結論から言うと、ボタンを追加したXMLファイルに
「android:descendantFocusability=”blocksDescendants”」を追加すると解決します。
こんな感じです。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="50dp"
android:minHeight="?attr/listPreferredItemHeight"
android:descendantFocusability="blocksDescendants" ←これを追加すれば良い
android:orientation="horizontal">
<TextView
android:id="@+id/title_list"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
↓追加したいボタン
<ImageButton
android:id="@+id/EditButton"
android:layout_width="10dp"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:src="?android:attr/actionModeCloseDrawable" />
</LinearLayout>
|
理由はよくわかりません。。わかったらまた追加記事書きます。

