在游标查询的行数限制 [英] Limit number of rows in Cursor query

查看:205
本文介绍了在游标查询的行数限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Android手机联系人。所以我用这个code:

I need to get contacts from an android phone. so I am using this code:

Cursor phones = getActivity().getContentResolver().query(Phone.CONTENT_URI,
    new String[] { Phone.NUMBER, Phone.TYPE },
    " DISPLAY_NAME = ?", new String[] { displayName }, null);
while (phones.moveToNext()) {
   //do work here
}

我要告诉光标限制的东西,如LIMIT 50应对50。我在哪里可以传递信息给光标?请复制并粘贴我的code,使编辑那里。

I want to tell the cursor to limit the response to 50 with something like "LIMIT 50". Where do I pass that information to the cursor? Please copy and paste my code and make edit there.

推荐答案

如果您有数据库,你可以使用表名,但内容供应商不必在他们的查询语句有限制的说法。

If you have the DB and the table name you can use that, but Content providers don't have a limit argument in their query statement.

mDb = new DBHelper (this);

Cursor c = mDB.getReadableDatase().query(
       <Phone_Table_Name>, 
       new String[] { Phone.NUMBER, Phone.TYPE }, 
       "DISPLAY_NAME = ?", 
       new String[] { displayName }, null), 
       null, 
       null, 
       null, 
       "50");

这篇关于在游标查询的行数限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆