简体   繁体   中英

retrieving data from firebase android

I am studying in France and I have trouble finding French tutorials to solve my problem. I am therefore obliged to ask my question, hoping to have a satisfactory solution.

My problem is that I have trouble reading my data on firebase and I have spent three days on it.

I have a structure like this:

I had started to code something, I was able to recover the key but I could not recuperate these values "nom" "argent" etc .

private Firebase mRef ;
mRef = new Firebase("https://authent-50e6b.firebaseio.com/users");
mRef.addChildEventListener(new ChildEventListener() { 
    @Override
   public void onChildAdded(DataSnapshot dataSnapshot, String s) {
        String cle = dataSnapshot.getKey();
        Toast.makeText(ListeActivity.this,"la cle est : "+cle ,Toast.LENGTH_SHORT).show();

An alternative to John's is to use DataSnapshot.child() to get to each property:

public void onChildAdded(DataSnapshot dataSnapshot, String s) {
    String cle = dataSnapshot.getKey();
    String nom = dataSnapshot.child("nom").getValue(String.class);
    Toast.makeText(ListeActivity.this,"la cle est : "+cle+" nom est : "+nom ,Toast.LENGTH_SHORT).show();

You would need something like following (assuming you have User pojo whose fields map to those in firebase db)

User user = dataSnapshot.getValue(User.class);
String nom = user.getNom();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM