Does someone know how to get a 'flat' map / list of the contacts and
there phone numbers. I am currently using this to build a datastructure,
so I can display it in a lIstView, which is not really fast. The code
shows that I do two queries. Would it be possible to do this with one
query so that I end up with a just one cursor. The structure ideally
would be:
contact name
number
number
contact name
number
This would then allow me with a custom listView Adapter to display the
data and make the names non clickable.
<code>
public List<ContactInfo> getContacts(Context ctx) {
// TODO Auto-generated method stub
String[] projection = new String[] { Contacts.People._ID,
Contacts.People.NAME, Contacts.People.NUMBER };
ContentResolver resolver = ctx.getContentResolver();
Cursor cur = resolver.query(Contacts.People.CONTENT_URI, null,
null, null, Contacts.People.DEFAULT_SORT_ORDER);
String name = "start_name_identitiy";
ArrayList<ContactInfo> contacts = new ArrayList<ContactInfo>();
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
ContactInfo info = new ContactInfo();
String id = cur.getString(cur.getColumnIndex(People._ID));
String dname =
cur.getString(cur.getColumnIndex(People.DISPLAY_NAME));
info.name = dname;
Cursor pCur =
resolver.query(Contacts.Phones.CONTENT_URI, null,
Contacts.Phones.PERSON_ID + " = ?", new String[] { id }, null);
int i = 0;
int pCount = pCur.getCount();
String[] phoneNum = new String[pCount];
String[] phoneType = new String[pCount];
while (pCur.moveToNext()) {
phoneNum[i] =
pCur.getString(pCur.getColumnIndex(Contacts.Phones.NUMBER));
//phoneType[i] =
pCur.getString(pCur.getColumnIndex(Contacts.Phones.TYPE));
if(phoneNum[i] != null) {
// info.numbers.add( dname );
info.numbers.add( phoneNum[i] );
}
i++;
}
if( info.numbers.size() > 0 ) contacts.add(info);
}
}
return contacts;
}
<!code>
Thank you.
Jiri
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
To unsubscribe, reply using "remove me" as the subject.