在我的Android应用程序中,我需要在列表视图中显示联系人列表..但是当我显示联系人时正在重复..如果有人可以建议我需要提供哪些更改,请给我下面的代码请帮助... iam我的代码在下面
Cursor c = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
while (c.moveToNext())
{
String contactName = c
.getString(c
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phNumber = c
.getString(c
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
boolean retval2 = contacts1.contains(contactName);
if (retval2 == false)
{
Contact con = new Contact(c.getString(c
.getColumnIndex(Contacts.DISPLAY_NAME)), c.getString(c
.getColumnIndex(Phone.NUMBER)));
contacts.add(con);
contacts1.add(contactName);
}
}
listView.setAdapter(new ContactsAdapter(this, contacts));
public class Contact
{
private String name;
private String mobile;
public Contact(String name, String mobile)
{
super();
this.name = name;
this.mobile = mobile;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getMobile()
{
return mobile;
}
public void setMobile(String mobile)
{
this.mobile = mobile;
}
}
答案 0 :(得分:-1)
这可能有助于删除重复项
if(!contacts.contains(con))
{
contacts.add(con);
}