ContentResolver query
来源:互联网 发布:mysql qq充值 编辑:程序博客网 时间:2024/04/25 12:05
- Cursor cursor = contentResolver.query(android.provider.ContactsContract.Contacts.CONTENT_URI,
- null, null, null, null);
public final Cursor query (Uri uri, String[] projection,String selection,String[] selectionArgs, StringsortOrder)
第一个参数,uri,rui是什么呢?好吧,上面我们提到了Android提供内容的叫Provider,那么在Android中怎么区分各个Provider?有提供联系人的,有提供图片的等等。所以就需要有一个唯一的标识来标识这个Provider,Uri就是这个标识,android.provider.ContactsContract.Contacts.CONTENT_URI就是提供联系人的内容提供者,可惜这个内容提供者提供的数据很少。第二个参数,projection,真不知道为什么要用这个单词,这个参数告诉Provider要返回的内容(列Column),比如Contacts Provider提供了联系人的ID和联系人的NAME等内容,如果我们只需要NAME,那么我们就应该使用:
- Cursor cursor = contentResolver.query(android.provider.ContactsContract.Contacts.CONTENT_URI,
- new String[]{android.provider.ContactsContract.Contacts.DISPLAY_NAME}, null, null, null);
第三个参数,selection,设置条件,相当于SQL语句中的where。null表示不进行筛选。如果我们只想返回名称为张三的数据,第三个参数应该设置为:
- Cursor cursor = contentResolver.query(android.provider.ContactsContract.Contacts.CONTENT_URI,
- new String[]{android.provider.ContactsContract.Contacts.DISPLAY_NAME},
- android.provider.ContactsContract.Contacts.DISPLAY_NAME + "='张三'", null, null);
- 11-05 15:30:32.188: I/System.out(10271): 张三
- Cursor cursor = contentResolver.query(android.provider.ContactsContract.Contacts.CONTENT_URI,
- new String[]{android.provider.ContactsContract.Contacts.DISPLAY_NAME},
- android.provider.ContactsContract.Contacts.DISPLAY_NAME + "=?",
- new String[]{"张三"}, null);
效果和上面一句的效果一样。
第五个参数,sortOrder,按照什么进行排序,相当于SQL语句中的Order by。如果想要结果按照ID的降序排列:
- Cursor cursor = contentResolver.query(android.provider.ContactsContract.Contacts.CONTENT_URI,
- null, null,null, android.provider.ContactsContract.Contacts._ID + " DESC");
- 11-05 16:00:32.808: I/System.out(12523): 31
- 11-05 16:00:32.808: I/System.out(12523): 李四
- 11-05 16:00:32.817: I/System.out(12523): 13
- 11-05 16:00:32.817: I/System.out(12523): 张三
- Cursor cursor = contentResolver.query(android.provider.ContactsContract.Contacts.CONTENT_URI,
- null, null,null, android.provider.ContactsContract.Contacts._ID + " ASC");
- 11-05 15:59:10.327: I/System.out(12406): 13
- 11-05 15:59:10.327: I/System.out(12406): 张三
- 11-05 15:59:10.327: I/System.out(12406): 31
- 11-05 15:59:10.327: I/System.out(12406): 李四
0 0
- ContentResolver query
- ContentResolver query 参数详解
- ContentResolver.query()的用法
- ContentResolver query 参数详解
- ContentResolver query 参数详解
- ContentResolver query 参数详解
- ContentResolver query 参数详解
- ContentResolver.query()的四个参数
- ContentResolver.query()的参数 说明
- ContentResolver.query()的参数 说明
- ContentResolver query()的四个参数
- ContentResolver.query()的四个参数
- Android ContentResolver query 参数详解
- Android ContentResolver query 参数详解
- ContentResolver.query方法的使用
- ContentResolver().query的分组查询
- ContentResolver query方法 参数详解
- 转载自司大可 ContentResolver query 参数详解
- mysql常用引擎以及各个引擎间的差异
- DigestUtils工具类
- Spring Init Destory
- 日期获取:得到当前月的第一天,得到当前月的最后一天
- hdu 4585- HDU 4585 Shaolin Treap + 寻找前驱后继 水
- ContentResolver query
- java枚举初解析
- Java线程Thread(三)
- 5. Longest Palindromic Substring--2016/09/27
- 欢迎使用CSDN-markdown编辑器
- 今日学习——素数及其优化
- 蜂鸣器的呐喊
- 专访左程云:5年刷题大牛分享算法学习之道
- 第一个OpenGL程序