Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

android - How can i retrieve a specific data from a firebase child node into Adnroid studio

enter image description here

referenc2= FirebaseDatabase.getInstance().getReference("messageCounter").child("node"); 
referenc2.addValueEventListener(new ValueEventListener() { 
  public void onDataChange(@NonNull DataSnapshot snapshot) { 
    String count= Integer.parseInt(snapshot.child("cnt").getValue(String.class)); 
  } 
  @Override public void onCancelled(@NonNull DatabaseError error) { 
  } 
});

I need to retrieve the value stored inside the cnt node into a variable in android studio. can anyone help?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

if you want to get value of specific node or child node like this

Here if you want to get child node(address) value. You can get it in this way

DatabaseReference db= FirebaseDatabase.getInstance().getReference().child("RouteCounter").child("node");

    
    db.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            for (DataSnapshot userSnapshot: dataSnapshot.getChildren()) {
                String email = userSnapshot.child("cnt").getValue(String.class);
            }
        }
    
        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            throw databaseError.toException();
        }
    });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...