我有2個列表,其中一個是名稱,另一個是數字。當我有點名稱列出其工作正常,但數量不與這些名字相匹配,這是我的代碼如何在android中一次對2個列表進行排序
try {
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER };
List<String> contactNames = new ArrayList<String>();
List<String> contactNumbers = new ArrayList<String>();
Cursor people = getContentResolver().query(uri, projection, null,
null, null);
int indexName = people
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
int indexNumber = people
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
people.moveToFirst();
do {
String name = people.getString(indexName);
String number = people.getString(indexNumber);
contactNames.add(name);
contactNumbers.add(number);
} while (people.moveToNext());
PhoneContactsAdapter adapter = new PhoneContactsAdapter(context,
contactNames, contactNumbers, selectedContacts);
Collections.sort(contactNames);
adapter.notifyDataSetChanged();
lv_contacts_phone.setAdapter(adapter);
lv_contacts_phone.setFastScrollEnabled(true);
} catch (Exception e) {
System.out
.println("(SELECTFRIENDSACTIVITY)Selecting contacts from friends: "
+ e);
}
這裏contactNames和contactNumbers被givent這裏的列表視圖lv_contacts_phone我只得到排序的名字和號碼不正確匹配與名稱請幫我
嘗試使用Collection.sort(名單); – abhi
@新白癡是正確的,使用自定義類,而不是排序它。請參閱此鏈接http://stackoverflow.com/questions/10091110/sorting-custom-class-array-list-string-using-collections-sort/10091403#10091403 –
@Hiren Dabhi在您的鏈接只使用一個列表。所以他可以分類聯繫人的姓名。但在我的代碼中,我想排序名稱以及代碼 – sarabu