how to get data from bottom to top from firebase?

无人久伴 提交于 2019-12-13 04:23:01

问题


I'm trying to get data from bottom to top (from the last item uploaded to the first item uploaded like Instagram) but I couldn't make this. I searched a lot and found this answer here.

I made it with firebaseRecyclerAdapter and worked fine but with custom Adapter I couldn't do it!

here is the method I used:

@Override
    public ItemsRecyclerView getItem(int pos){
        return super.getItem(getCount() - 1 - pos);
    }

回答1:


What you should be doing is reversing the recyclerview, forget about the method that you used above.

And do this when you set your recycler view:

LinearLayoutManager manager = new LinearLayoutManager(context);
manager.setReverseLayout(true);
manager.setStackFromEnd(true);
recycler_View.setLayoutManager(manager);

Possible solution:

try this:

Maybe try to reverse the list that you pass to your adapter like this:

//your list
List<model> your_list = new ArrayList()<>;

//before you pass it to the adapter do this
Collections.reverse(your_list);

//now your list is reversed, pass it to the adapter
Adapter adapter = new Adapter (your_list,.....,....);


来源:https://stackoverflow.com/questions/51059383/how-to-get-data-from-bottom-to-top-from-firebase

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