弱龄寄事外,委怀在琴书。这篇文章主要讲述sql android忽略重复检索内容相关的知识,希望能为你提供帮助。
【sql android忽略重复检索内容】帮我解决这个问题,以删除我从数据库中获得的重复联系人
cursor= getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.Data.DATA1 + "!=''",null,"upper("+ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + ") ASC");
答案 use this code to contact list from mobile database and set on list viewNo duplicate data retreive.
public void customgetContactList()
{
String SELECTION = "((" +
ContactsContract.Data.DISPLAY_NAME + " NOTNULL) AND (" +
ContactsContract.Data.DISPLAY_NAME + " != '"+checkDuplicacy+"' ))";
Cursor cursor= getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
SELECTION,null,"upper("+ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + ") ASC");
int ColumeIndex_ID = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID);
int ColumeIndex_DISPLAY_NAME = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
int ColumeIndex_HAS_PHONE_NUMBER = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
ArrayList<
HashMap<
String,String>
>
arrayList=new ArrayList<
>
();
while (cursor.moveToNext()){
String id = cursor.getString(ColumeIndex_ID);
String name = cursor.getString(ColumeIndex_DISPLAY_NAME);
String has_phone = cursor.getString(ColumeIndex_HAS_PHONE_NUMBER);
//phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA));
if (!name.equals(checkDuplicacy) &
&
!has_phone.equals(checkDuplicacynumber))
{HashMap<
String,String>
hashMap=new HashMap<
>
();
//create a hashmap to store the data in key value pair
hashMap.put("name",name);
hashMap.put("phone",has_phone);
arrayList.add(hashMap);
String[] from = {"name","phone"};
int[] to = {R.id.textViewName,R.id.textviewnumber};
SimpleAdapter simpleAdapter=new SimpleAdapter(this,arrayList,R.layout.customtextviewforlist,from,to);
//SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(this,R.layout.customtextviewforlist,cursor,from,to);
//startManagingCursor(cursor);
contactListView.setAdapter(simpleAdapter);
contactListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
checkDuplicacy=name;
checkDuplicacynumber=has_phone;
}
}
}
推荐阅读
- SQLite Android数据库游标窗口分配2048 kb失败
- 可能尚未为Cursor android初始化局部变量
- Android(无法从CursorWindow读取第0行,第3列。在从中访问数据之前,请确保正确初始化Cursor)
- 如何在android中使用游标(sqlite查询)搜索数据库
- 在Glassfish 5.0中部署ADF WEbapp时出错
- 如何为Electron / Atom Shell App设置应用程序图标
- 我在哪里可以找到Android的默认图标( [重复])
- 如何在android studio中更改图标颜色
- Android Studio编译旧图标