我试图Messages/child在基础上检索排序time。我可以访问Messages/child。我找不到任何有用的解决方案。请帮我解决这个问题。我目前的代码是:FirebaseDatabase.getInstance()
.getReference()
.child("Messages")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable, String s) {
Log.d("children",dataSnapshot.getKey());
users_list.add(dataSnapshot.getKey());
}
3 回答
万千封印
TA贡献1891条经验 获得超3个赞
你可以这样做: -
mChatReference = FirebaseDatabase.getInstance().getReference("Messages") .child(FirebaseAuth.getInstance().getCurrentUser().getUid()); Query query = mChatReference.orderByChild("time"); query.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { Log.d("children",dataSnapshot.getKey()); users_list.add(dataSnapshot.getKey()); } @Override public void onCancelled(@NonNull DatabaseError databaseError) { } });
不负相思意
TA贡献1777条经验 获得超10个赞
试试这个..
DocumentReference docRef = FirebaseFirestore.getInstance().collection(YOUR_COLLECTION).document(FirebaseAuth.getInstance(). getCurrentUser().getUid());docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() { @Override public void onComplete(@NonNull Task<DocumentSnapshot> task) { if (task.isSuccessful()) { DocumentSnapshot document = task.getResult(); if (document.exists()) { if (document.contains("message")) { String message=document.get("message").toString()); } //add other information to your user_list } } }});
没有找到匹配的内容?试试慕课网站内搜索吧
添加回答
举报
0/150
提交
取消