码迷,mamicode.com
首页 > 移动开发 > 详细

Android CursorAdapter 查询联系人过滤

时间:2014-07-01 19:52:14      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   color   使用   数据   

一、使用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 查询联系人过滤

标签:android   style   blog   color   使用   数据   

原文地址:http://www.cnblogs.com/sigmon/p/3816994.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!