How to implement infinite scroll with RecyclerView in Android using Parse

别说谁变了你拦得住时间么 提交于 2019-11-29 23:26:46

问题


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.

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.

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


回答1:


Finally I solved it by using setSkip function.

Code:

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; 
            }

        });


来源:https://stackoverflow.com/questions/33889157/how-to-implement-infinite-scroll-with-recyclerview-in-android-using-parse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!