首页 > 代码库 > Android CursorAdapter 查询联系人过滤
Android CursorAdapter 查询联系人过滤
一、使用sqlite 数据库查询时,用于模糊查询的方法
like
% : 表示有0个或多个字符
_ : 表示1个字符
二、去掉联系人电话号码中的空格:
"replace"(data1, ‘ ‘, ‘‘) LIKE ‘13_________‘
三、查询符合手机号码格式的号码
public Loader<Cursor> onCreateLoader(int id, Bundle args) { String phone = "\"replace\"(" + ContactsContract.CommonDataKinds.Phone.NUMBER + ",‘ ‘,‘‘)"; String expression = phone + " LIKE ? or " + phone + " LIKE ? or (" + phone + " LIKE ? and " + phone + " NOT LIKE ?)" + " or " + phone + " LIKE ? or " + phone + " LIKE ? or (" + phone + " LIKE ? and " + phone + " NOT LIKE ?)" + " or " + phone + " LIKE ? or " + phone + " LIKE ? or (" + phone + " LIKE ? and " + phone + " NOT LIKE ?)"; String[] filter = new String[]{ "13_________", "18_________" , "15_________", "154________", "013_________", "018_________", "015_________", "0154________", "+8613_________", "+8618_________", "+8615_________", "+86154________"}; CursorLoader cursorLoader = new CursorLoader(InvitePeopleActivity.this, ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER}, expression, filter, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME); return cursorLoader;}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。