重复的联系人不显示在listiview中 [英] duplicate contacts not to show in listiview
本文介绍了重复的联系人不显示在listiview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个可在Listview中显示联系人号码的应用程序,但它却给出了重复的联系人条目,我只想单独显示一个联系人
i am making an app to show contacts number in a Listview but it is giving duplicate contacts entries i wanted to only show one contact singly
private void getContactList() {
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
if ((cur != null ? cur.getCount() : 0) > 0) {
while (cur != null && cur.moveToNext()) {
String id = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(
ContactsContract.Contacts.DISPLAY_NAME));
if (cur.getInt(cur.getColumnIndex(
ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
Cursor pCur = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
String phoneNo = pCur.getString(pCur.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
ContactsPlacer obj = new ContactsPlacer();
obj.setContactname(name);
obj.setContactnumber(phoneNo);
names.add(obj);
}
pCur.close();
}
}
}
if(cur!=null){
cur.close();
}
}
帮我解决一下,重复的联系人不在列表视图中显示
help me about it that the duplicate contacts not show in listview
推荐答案
boolean checkexsistance(ContactsPlacer obj)
{
boolean test= true;
for(int i = 0 ; i<names.size();i++)
{
if(names.get(i).getContactname().equals(obj.getContactname()))
{
test = false;
break;
}
}
return test;
}
private void getContactList() {
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
if ((cur != null ? cur.getCount() : 0) > 0) {
while (cur != null && cur.moveToNext()) {
String id = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(
ContactsContract.Contacts.DISPLAY_NAME));
if (cur.getInt(cur.getColumnIndex(
ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
Cursor pCur = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
String phoneNo = pCur.getString(pCur.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
ContactsPlacer obj = new ContactsPlacer();
obj.setContactname(name);
obj.setContactnumber(phoneNo);
if(checkexsistance(obj))
names.add(obj);
}
pCur.close();
}
}
}
if(cur!=null){
cur.close();
}
}
这篇关于重复的联系人不显示在listiview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文