我无法在日期字段(时间戳)上使用orderByChild订购结果
这里的数据结构:
代码:
DatabaseReference mMessagesRef = FirebaseDatabase.getInstance().getReference().child("messages")
.child(mConversationId).getRef()
.orderByChild("date").getRef();
mMessagesRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot data: dataSnapshot.getChildren()){
查询返回了值,但没有按日期排序,它按键返回..
答案 0 :(得分:4)
Try this:
DatabaseReference mMessagesRef=FirebaseDatabase.getInstance().getReference();
Query queryRef = mMessagesRef.child("messages").orderByChild("date");
queryRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot data: dataSnapshot.getChildren()){