在contentProvider中选择前n行

Gel*_*ude 7 android where android-contentprovider

我选择这个:

 final Cursor cursorConversations = getContentResolver().query(
        Uri.parse("content://gmail-ls/conversations/" + Uri.encode(mailAddress)),
        null, null, null, BaseColumns._ID + " DESC");

 ContentQueryMap mQueryMap 
        = new ContentQueryMap(cursorConversations, BaseColumns._ID, true, null);
Run Code Online (Sandbox Code Playgroud)

使用ContentQueyMap,我可以缓存Cursor数据并在Cursor关闭时迭代它(我需要它来提升性能).

现在,我想要选择Corsor只检索前五十行.循环50次的解决方案mQueryMap.getRows().entrySet()是不对的:我不希望mQueryMap获取Cursor的所有行,但只需要前五十行.

任何的想法?是否存在where子句只能获得前n行?

Chr*_*ins 14

你可以做到

final Cursor cursorConversations = getContentResolver().query(
    Uri.parse("content://gmail-ls/conversations/" + Uri.encode(mailAddress)),
    null, null, null, BaseColumns._ID + " DESC " + " LIMIT 5");
Run Code Online (Sandbox Code Playgroud)

排序后"LIMIT x".

干杯