如何使用 Parse 在 Android 中使用 RecyclerView 实现无限滚动 [英] How to implement infinite scroll with RecyclerView in Android using Parse

查看:30
本文介绍了如何使用 Parse 在 Android 中使用 RecyclerView 实现无限滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上找到的大多数文章都使用 setLimit 函数来加载更多项目.但这不是一种有效的方式,因为我们会调用现有的对象.

Most of the articles I found online used setLimit function to load more items. But it is not an efficient way as we would be recalling the existing objects.

我正在使用带有自定义适配器的 RecyclerView 来加载我的列表项.一旦我从 Parse 服务器收到对象列表,我就会根据我的算法将几个项目分组并将其传递给我的自定义适配器.

I'm using a RecyclerView with a custom adapter to load my list items. Once I receive the list of objects from Parse server, I group few items based on my algorithm and pass it to my Custom Adapter.

我知道 ParseQueryAdapter 是另一种实现分页的方法.有人可以建议我如何将 ParseQueryAdapter 与我的自定义适配器一起使用吗?

I got to know that ParseQueryAdapter is another way to implement pagination. Can someone suggest how I can use ParseQueryAdapter with my custom adapter?

推荐答案

最后我用 setSkip 函数解决了.

Finally I solved it by using setSkip function.

代码:

private int limit =0; 
private boolean loadMore = false;  



ParseQuery<ParseObject> query = ParseQuery.getQuery("ClassName");

if(loadMore==true)
    {
        query.setSkip(limit); 
        query.setLimit(12);
    } 
    else
    {
        query.setLimit(12); 
    }

query.findInBackground(new FindCallback<ParseObject>() 
     {

        @Override
        public void done(List<ParseObject> arg0, ParseException arg1) 
        { 
            limit = limit+ arg0.size(); 

            if(arg0.size()==0)
            {
                loadMore = false; 
            }
            else
            {
                loadMore = true; 
            }

        });

这篇关于如何使用 Parse 在 Android 中使用 RecyclerView 实现无限滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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