查询内容

  

和数据库中一样,查询的结果以一个指向结果集的Cursor返回。你可以使用在之前的关于数据库“提取结果”章节中描述的技巧来提取结果。

 

Content Provider的查询传入的参数和数据库查询非常相似。在ContentResolver对象上使用qurey方法,传入:

 

你想查询的数据的URI

 

你想在结果集中包含的列项。

 

where语句,定义了要返回的行。你可以包含?通配符,它将被selectionArgs参数中储存的值替换。

 

字符串数组,它将替换where语句中的?。

 

一个描述返回行的顺序的字符串。

 

下面的代码片段演示了使用ContentResolver来对Content Provider应用查询。

 

// Return all rows

Cursor allRows = getContentResolver().query(MyProvider.CONTENT_URI, null, null, null, null);

 

// Return all columns for rows where column 3 equals a set value

// and the rows are ordered by column 5.

String where = KEY_COL3 + “=” + requiredValue;

String order = KEY_COL5;

Cursor someRows = getContentResolver().query(MyProvider.CONTENT_URI, null, where, null, order);

 

当介绍Android本地的Content Provider时,你将看到更多的关于查询内容的实际例子。

posted on 2009-08-07 17:08  xirihanlin  阅读(663)  评论(0编辑  收藏  举报