リスト ビューで連絡先を取得しようとしています。を使用すると複数の連絡先を選択できることがわかりsimple_list_item_multiple_choice
ましたが、数字のない名前のみが表示されます。
反対側でsimple_list_item_2
は、名前と番号の両方を表示するために使用できますが、1 つの連絡先のみを選択できます。
両方を組み合わせたテンプレートはありますか?そうでない場合、両方の機能を備えたカスタマイズされたリストを作成するにはどうすればよいですか?
編集:これは私が使用しているコードです
CursorLoader cl = new CursorLoader(this,ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PROJECTION, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME+" ASC");
Cursor c = cl.loadInBackground();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, // Use a template
// that displays a
// text view
c, // Give the cursor to the list adapter
new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME},
new int[] { android.R.id.text1},0);
setListAdapter(adapter);
ここで、SimpleCursorAdapter の 2 番目のパラメーターは ですが、これは のsimple_list_item_multiple_choice
処理のみをサポートしていandroid.R.id.text1
ます。したがって、サブアイテムではなく、アイテムのみを使用できます。
しかし、次のコードでは
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_expandable_list_item_2, // Use a template
// that displays a
// text view
c, // Give the cursor to the list adapter
new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ,ContactsContract.CommonDataKinds.Phone.NUMBER},
new int[] { android.R.id.text1,android.R.id.text2},0);
と の両方ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME
を指定してとNUMBER
で書くことはできますが、複数選択機能は使用できません。android.R.id.text1
android.R.id.text2