如何通过重播时间戳在Firebase中订购Recyclerview项目

时间:2018-08-13 11:41:09

标签: android

我如何订购这样的recyclerview物品

mDatabaseReference = FirebaseDatabase.getInstance().getReference();
productQuery = mDatabaseReference.child("Blog").orderByChild("replaydate");

“重播日期”位于Replay> psotkey>重播日期我想按还款日期订购博客项目,这可能吗?

this image show my database

1 个答案:

答案 0 :(得分:0)

如果要按时间戳顺序获取消息,可以使用

 database.orderByChild("replydate").limitToLast(10)
                .addChildEventListener(new ChildEventListener() {
    @Override
    public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                if (dataSnapshot.getValue() != null) {
    Model newModel = dataSnapshot.getValue(Model.class);  
//Model is you model which you are using for showing data in recyclerview
    arraylist.add(newModel);
    adapter.notifyDatasetChanged();
    }

    @Override
    public void onChildChanged(DataSnapshot dataSnapshot, String s) {
    }

    @Override
    public void onChildRemoved(DataSnapshot dataSnapshot) {

    }

    @Override
    public void onChildMoved(DataSnapshot dataSnapshot, String s) {

    }

    @Override
    public void onCancelled(DatabaseError databaseError) {

    }
});