一、使用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; }
Android CursorAdapter 查询联系人过滤
时间: 2024-10-13 16:03:39