[英]How can i retrieve specific list items on Firebase Databse on Android
teamapp-25ba7
schedules
-LHc3zKZhNFLq536dpA1
UID:
date:
details:
time:
title:
-LHc7MBAoNwLWCNgkZ_y
UID:
date:
details:
time:
title:
from the above example of my nodes, i would like to just get details and time values ,my question is how do i retrieve just those 2 values . 从上面的节点示例中,我只想获取详细信息和时间值,我的问题是如何只检索这两个值。 i tried iterating through all the values but that just gets me everything 我尝试遍历所有值,但这让我得到了一切
Assuming that you want to get the values of details
and time
properties from all objects and also assuming that the details
property is of type String and the time
is ServerValue.TIMESTAMP , to solve this please use the following code: 假设你想要得到的值details
和time
的所有对象的属性,并假设details
属性是String类型和time
是ServerValue.TIMESTAMP ,要解决这个,请使用如下代码:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference schedulesRef = rootRef.child("schedules");
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String details = ds.child("details").getValue(String.class);
long time = ds.child("time").getValue(Long.class);
Log.d("TAG", details + " / " + time);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {}
};
schedulesRef.addListenerForSingleValueEvent(valueEventListener);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.