Skip to content Skip to sidebar Skip to footer

Firebase Value Event Listener

I want to read the values from Firebase Database and show in a ListView. But something gone wrong. It's not giving correct values. Here is the code: Java final FirebaseDatabas

Solution 1:

Egek92's answer is right. And I think I know why it doesn't provide data you want. Maybe with this following code, you will:

DatabaseReferencereference= database.getReference("Stats").child("Matematik");
reference.addValueEventListener(newValueEventListener() {
    @OverridepublicvoidonDataChange(DataSnapshot dataSnapshot) {
        // dataSnapshot value will be Matematik, {ahmetozrahat=50, nihatkeklik=50}// because it is indeed the value we need// But you want key value pair to be added to your stats// So we can just loop through the valuesfor (DataSnapshot childSnapshot : dataSnapshot.getChildren()) {
            stats.put(childSnapshot.getKey(), childSnapshot.getValue().toString());
        }
        StatsAdapteradapter=newStatsAdapter(stats);
        listView.setAdapter(adapter);
    }
    ...
}

Hope this helps

Solution 2:

Post a Comment for "Firebase Value Event Listener"