public class PendingReqFragment extends android.app.Fragment {
public PendingReqFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView =inflater.inflate(R.layout.pending_req, container, false);
return rootView;
}
我想从sahil
节点的所有子节点检索所有查询名称,并在ListView
中动态显示。
这是数据库的screenshot。
{
"query" : {
"sahil" : [ null, {
"address" : "bdbdbdb",
"name" : "sahildeep",
"no" : "64649",
"pincode" : "373737",
"query" : "hdbdbdvd",
"user_name" : "sahil"
}, {
"address" : "zbxbbx",
"name" : "sahil mehra",
"no" : "949495",
"pincode" : "1345",
"query" : "snxbxb",
"user_name" : "sahil"
} ]
}
}
答案 0 :(得分:0)
您需要在数据库中创建对子项的引用:
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myPostReference = database.getReference("message").child("child1");
然后在该引用上设置ValueEventListener以获取DataSnapshot:
ValueEventListener postListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Get Post object and use the values to update the UI
Post post = dataSnapshot.getValue(Post.class);
// ...
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// ...
}
};
mPostReference.addValueEventListener(postListener);
Firebase docs
中有更详细的信息