首页 > 移动平台 > 详细

Android CursorAdapter 查询联系人过滤

时间:2014-07-01 19:51:54      阅读:348      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!