如何获得我的Android 2.1的单独的ListView android的联系人列表中的数据? [英] how to get android contact list data on my seperate listview in android 2.1?
问题描述
我已创建了一个listview.now我要显示的数据(不接触,名称)从机器人(电话簿)的contactlist我的列表视图。
我得到它为Android 1.5,但我想这样做对android2.1updated。
i have created one listview.now i want to show data(contact no.,name) from contactlist of android(Phonebook) on my listview. i got it for android 1.5 but i want to do it for android2.1updated.
怎么办呢?任何一个可以指导我,或给一些示例code?
在此先感谢---
How to do it?can any one guide me or give some sample code? Thanks in advance---
推荐答案
如果您在1.5实现它,然后可以有URI的一个小的差异。你应该去更新在2.1 /更改联系人的URI。因为在这里进一步的了解是一个示例code代表2.1updated:
If you have achieved it in 1.5 then there can be a small difference of URI. You should go for updated/changed URI of Contacts in 2.1. For further understanding here is a sample code for 2.1updated:
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cur.moveToNext())
{
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
//---------------------------------------- Contact Names
//------------------------------------------------------
String DisplayName = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
Cursor names = cr.query(ContactsContract.Data.CONTENT_URI, null,ContactsContract.Data.CONTACT_ID + " = " + id, null, null);
names.moveToNext();
String GivenName = names.getString(names.getColumnIndex(ContactsContract.Data.DATA2));
String FamilyName = names.getString(names.getColumnIndex(ContactsContract.Data.DATA3));
String MiddleName = names.getString(names.getColumnIndex(ContactsContract.Data.DATA5));
names.close();
//----------------------------------------- Phone Numbers
//-------------------------------------------------------
String hasPhoneNumber = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (hasPhoneNumber.equals("1"))
{
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ id,null, null);
while (phones.moveToNext())
{
......
}
}
} // AND SO ON.... Get which ever data you need.
所以上面只是一个示例code,我用我的任务。你可以让你通过相应地更改需要的东西。我希望它能帮助。
so above is just a sample code that I used for my task. You can get what you need by making changes accordingly. I hope it helps.
这篇关于如何获得我的Android 2.1的单独的ListView android的联系人列表中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!