我一直在练习在 android 中阅读联系人,我得到了联系人和号码,但它们排列得不好。我的意思是分配的名称不是号码的所有者。这是我的代码:
String [] projection= new String[]{ContactsContract.Contacts.DISPLAY_NAME,};
String [] phoneProjection= new String [] {Phone.NUMBER};
ContentResolver crInstance=getContentResolver();
final Cursor name=crInstance.query(ContactsContract.Contacts.CONTENT_URI, projection, null, null, null);
final Cursor phone=crInstance.query(Phone.CONTENT_URI, phoneProjection, null, null, null);
contactview = (TextView) findViewById(R.id.contactview);
name.moveToFirst();
phone.moveToFirst();
while (!name.isAfterLast()&&!phone.isAfterLast()){
String pname=name.getString(name.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
contactview.append("Name:");
contactview.append(pname);
contactview.append("\n");
final int contactNoColIndex= phone.getColumnIndex(Phone.NUMBER);
String pnumber=phone.getString(contactNoColIndex);
contactview.append("Phone:");
contactview.append(pnumber);
contactview.append("\n");
contactview.append("\n");
name.moveToNext();
phone.moveToNext();
}
name.close();
phone.close();
请帮忙