我試圖讓我的聯繫人在列表視圖上。現在我知道使用simple_list_item_multiple_choice
可以讓我選擇多個聯繫人,但它僅查看沒有數字的姓名。Android:啓用了多項選擇和子項目的ListView
另一方面,simple_list_item_2
可用於顯示姓名和號碼,但支持只選擇一個聯繫人。
是否有任何模板將它們結合在一起?如果不是的話,我怎樣才能用這兩種功能構建自定義列表?
編輯:這是我使用
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的第二個參數是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
,但不能使用多選功能。
你可以把你使用的一些代碼?這將有很大幫助。 – Heejin
您應該根據您的要求定製您的佈局。 – Dilip
Heejin,完成。謝謝:) –