[英]Content provider - multiple where parameters
我是内容提供商的新手,为了理解和创建自定义内容提供商,我一直在参考本文档。
我在内容提供者的内容描述符类中具有这样的路径:
public static final String PATH = "tbl_reco_index_contents";
public static final String PATH_FOR_ID = "tbl_reco_index_contents/*";
使用以下代码,我可以从所需的列中获取数据,而不会出现任何问题:
public static final String AUTHORITY = "com.nyk.launcherprovider";
private static final Uri BASE_URI = Uri.parse("content://" + AUTHORITY);
public static final String PATH = "tbl_reco_index_contents";
public static final Uri CONTENT_URI = BASE_URI.buildUpon().appendPath(PATH).build();
cur = this.getContentResolver().query(CONTENT_URI, new String[]{
"reco_index_content_name",
"reco_index_content_url"
}, null, null, null);
cur.moveToFirst();
for(int i=0;i<cur.getCount();i++){
System.out.println("Name is:"+cur.getString(10));
System.out.println("URL is:"+cur.getString(11));
cur.moveToNext();
}
我不知道如何在这里使用where条件获取数据。 即; 如果我需要添加WHERE user_profile_number = 2 and pkg_name = 'abc'
,该如何与上面的代码一起处理。
任何帮助深表感谢。
当您使用波纹管语句时,它将在内容提供程序中调用PATH
Cursor cursor = getContentResolver().query(YOUR_URI, null, "user_profile_number = ? AND pkg_name = ? ", new String[]{"2", "abc"}, null);
如果要基于ID调用数据,则意味着您要调用PATH_FOR_ID,然后使用
Cursor cursor = getContentResolver().query(ContentUris.withAppendedId(CONTENT_URI, id), null, null, null, null);
采用
cur = this.getContentResolver().query(CONTENT_URI, new String[]{
"reco_index_content_name",
"reco_index_content_url"
}, "user_profile_number = 2 and pkg_name = 'abc'", null, null, null, null);
这里使用的功能是
公共游标查询(字符串表,字符串[]列,字符串选择,字符串[] selectionArgs,字符串groupBy,具有字符串,字符串orderBy)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.