我使用Firebase數據庫開發應用程序。我正在接收數據並上傳它沒有問題,但我想將數據添加到數據庫數組的頂部,而不是數據庫數組的底部。如何從recyclerview中的Firebase數據庫從底部到頂部檢索數據,或者如何在Firebase數據庫頂部添加數據?
所以建議我可以幫助我從底層到頂層檢索數據,或者我可以將其上傳到我的數據庫數組頂端。提前致謝。請幫助我。
我使用Firebase數據庫開發應用程序。我正在接收數據並上傳它沒有問題,但我想將數據添加到數據庫數組的頂部,而不是數據庫數組的底部。如何從recyclerview中的Firebase數據庫從底部到頂部檢索數據,或者如何在Firebase數據庫頂部添加數據?
所以建議我可以幫助我從底層到頂層檢索數據,或者我可以將其上傳到我的數據庫數組頂端。提前致謝。請幫助我。
有幾種方法可以做到這一點。
第一:
實施FirebaseUI,然後執行以下操作:
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(layoutManager)
二:
我更喜歡這種方式,特別是如果你計劃實施的一個GridLayoutManager未來。請注意,GridLayoutManager不支持setStackFromEnd();
。以下將允許您在「AdapterView」中反轉任何數據。
在你RecyclerViewAdapter
@Override
public Item getItem(int pos) {
return super.getItem(getCount() - 1 - pos);
}
的StackOverflow是不是爲您提供的作品的代碼。你試過什麼了? – jhhoff02
我嘗試** notifyItemInserted(0); **與FirebaseRecyclerAdapter,但不工作 – sam