如何从Firebase的底部到顶部获取数据? [英] how to get data from bottom to top from firebase?
问题描述
我试图从下到上获取数据(从上传的最后一个项目到像Instagram这样上传的第一个项目),但是我做不到.我进行了很多搜索并找到了这个答案
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.
我用firebaseRecyclerAdapter做到了,并且工作正常,但是使用自定义适配器我做不到!
I made it with firebaseRecyclerAdapter and worked fine but with custom Adapter I couldn't do it!
这是我使用的方法:
@Override
public ItemsRecyclerView getItem(int pos){
return super.getItem(getCount() - 1 - pos);
}
推荐答案
您应该做的是反转recyclerview,忘记上面使用的方法.
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);
可能的解决方案:
尝试一下:
也许尝试像这样反转您传递给适配器的列表:
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,.....,....);
这篇关于如何从Firebase的底部到顶部获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!