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;

}

Android CursorAdapter 查询联系人过滤,布布扣,bubuko.com

Android CursorAdapter 查询联系人过滤

上一篇:Socket实现异步通信


下一篇:从零开始学ios开发(十三):Table Views(下)Grouped and Indexed Sections