如何使用内容提供程序添加限制条款 [英] How to add limit clause using content provider

查看:25
本文介绍了如何使用内容提供程序添加限制条款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法限制从内容提供者返回的行数?我找到了这个解决方案,但是,它对我不起作用.仍在返回所有行.

Is there a way to limit the number of rows returned from content provider? I found this solution, however, it did not work for me. All of the rows are still being returned.

Uri uri = Playlists.createIdUri(playlistId); //generates URI
uri = uri.buildUpon().appendQueryParameter("limit", "3").build();     
Cursor cursor = activity.managedQuery(playlistUri, null, null, null, null);

推荐答案

我遇到了这个问题,不得不绞尽脑汁,直到我终于弄明白了,或者说找到了对我有用的方法.试试下面的

I have had this issue and had to break my head till I finally figured it out, or rather got a whay that worked for me. Try the following

Cursor cursor = activity.managedQuery(playlistUri, null, null, null, " ASC "+" LIMIT 2");

最后一个参数用于 sortOrder.我提供了排序顺序并附加了 LIMIT.确保正确分配空格.我不得不检查正在形成的查询,这似乎有效.

The last parameter is for sortOrder. I provided the sort order and also appended the LIMIT to it. Make sure you give the spaces properly. I had to check the query that was being formed and this seemed to work.

这篇关于如何使用内容提供程序添加限制条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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