我試圖創建一個「select-multiple」聯繫人列表,我可以讓用戶檢查多個聯繫人。我正在尋找的東西與向多個聯繫人撰寫郵件時出現的本地活動實際上是一樣的。謝謝!Android Contact Picker Checklist
3
A
回答
1
首先,您需要獲取聯繫人列表,然後將其顯示在ListView元素上。比如我用下面的代碼來顯示所有用戶在一個ListView聯繫人:
// Run query on all contacts id
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] { ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME};
String selection = null;//ContactsContract.Contacts.HAS_PHONE_NUMBER + " = '" + ("1") + "'";
String[] selectionArgs = null;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
+ " COLLATE LOCALIZED ASC";
ContentResolver contectResolver = getContentResolver();
Cursor cursor = contectResolver.query(uri, projection, selection, selectionArgs,
sortOrder);
//Create buffer
final ArrayList<ContactData> bufferContacts = new ArrayList<ContactData>();
//Load contacts one by one
if(cursor.moveToFirst()) {
while(!cursor.isAfterLast()) {
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String[] emailProj = new String[]{Email.DATA};
Cursor cursorEmail = contectResolver.query(Email.CONTENT_URI, emailProj,Email.CONTACT_ID + " = ? ", new String[] { id }, null);
String[] phoneProj = new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME};
Cursor cursorPhone = contectResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, phoneProj,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
String firstName = "";
String lastName = "";
String email = "";
String displayname = "";
String phoneNmb = "";
if(cursorPhone.moveToFirst()) {
///displayname = cursorPhone.getString(cursorPhone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
phoneNmb = cursorPhone.getString(cursorPhone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
cursorPhone.close();
if(cursorEmail.moveToFirst()) {
email = cursorEmail.getString(cursorEmail.getColumnIndex(Email.DATA));
}
cursorEmail.close();
displayname = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
//Divide display name to first and last
String[] names = displayname.split("\\s+");
firstName = displayname;
if(names.length >= 1) {
firstName = names[0];
}
if(names.length >= 2) {
firstName = names[1];
}
final ContactData contactData = new ContactData(id, firstName, lastName, phoneNmb, email, allChecked);
bufferContacts.add(contactData);
//Set list view initialy
runOnUiThread(new Runnable() {
public void run() {
if(contactsAdapter == null) {
ArrayList<ContactData> contacts = new ArrayList<ContactData>();
contactsAdapter = new ContactAdapter(ContactPickerActivity.this, contacts);
lvContacts.setAdapter(contactsAdapter);
}
if(bufferContacts.size() >= BUFFER_INTERVAL) {
addBuffer(bufferContacts);
}
}
});
cursor.moveToNext();
}
}
cursor.close();
runOnUiThread(new Runnable() {
public void run() {
addBuffer(bufferContacts);
}
});
如果你不想打擾一下讓一切從頭開始出來的那麼隨意使用我準備庫選擇多聯繫人:
https://github.com/kgadzinowski/Android-Multiple-Contacts-Picker-Library
+0
你還沒有提到如何使用你的庫和支持gradle,它會很容易使用和幫助。 – 2015-09-26 13:21:49
相關問題
- 1. Android Color Picker
- 2. Android Studio Calendar Picker
- 3. 有一個像Pick Picker Android的SMS Picker?
- 4. Phonegap android handle null contact image
- 5. Android Date Picker pre 1900
- 6. Android Date Picker幫助!
- 7. Zenity --list --checklist問題
- 8. 從SQLite填充CheckList
- 9. 定製Style CheckList RadTreeView
- 10. PHP Todo CheckList Checked Feature
- 11. iOS AddressBookUI - '不應該試圖顯示多個Add to Existing Contact people picker。「
- 12. Android 4.1.1/4.1.2 Date Picker Galaxy S3
- 13. Android Place Picker:完整說明
- 14. 帶字符串的Android Picker
- 15. 如何讓android raw-contact溝通intent?
- 16. linux對話框--checklist錯誤
- 17. PersistenceSpecification CheckList與私有財產
- 18. Magento Contact Form change
- 19. Google Apps Contact Sync
- 20. Contact Form + jQuery validationengine
- 21. Adwords Contact Form Tracking
- 22. Blackberry Contact Listener
- 23. Sencha iOS picker bug
- 24. Cocoa:Time Picker
- 25. didBeginContact:(SKPhysicsContact *)contact not invoked
- 26. WP-Contact Form 7 - PHP
- 27. mail_form gem for Contact Form
- 28. PHP Contact Form not working
- 29. Android - Picker來選擇多個視頻
- 30. 如何使用devmil-android-color-picker?
試圖與ContactsContract的東西,但1.6 compat的將是很好。我的問題是與複選框部分。在消息傳遞中,Android是否具有某種帶有複選框的本地聯繫人選擇器? – Will 2010-09-11 21:01:04