複数選択できるリストビューを作成したいと思います。一般的な解決策は、カーソルを取得してSimpleCursorAdapterを使用することです。
SimpleCursorAdapter adapter2 = new SimpleCursorAdapter(this,
R.layout.simple_list_item_multiple_choice, cur2, cols2, views2);
を使用すると、これを機能させることができR.layout.simple_list_item_multiple_choice
ます。複数の項目を選択すると、チェックマークが機能します。
そこで、カスタムメイドのレイアウトで試してみることにしました。これが私のレイアウトのXMLコードです。
<?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:orientation="vertical" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/lookup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/hasphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" />
<CheckedTextView
android:id="@+id/checkedTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"/>
</LinearLayout>
これが私の問題です。同じコードを使用し、リストビューでChoiceModeを複数に設定すると、レイアウトがうまく膨らみます。カーソルからのデータは正常に入力されます。
しかし、私が抱えている問題は、アイテムをクリックしたときにチェックマークが選択されたものとして表示されないことです(ボックスのチェックボックス)。カスタムアダプタの作成を伴わない、私が見逃しているものはありますか?
l2.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
l2は私のリストビューです。