How To Get All Child Node List Values From Firebase Database?
So this is how my database looks like. Each user can add his 3 best players that are stored in userId/My Players/ path as a Map<'Best Players', Player> as it is shown here:
Solution 1:
In order to display those lists, please use this code:
ListView listView = (ListView) findViewById(R.id.list_view);
ArrayList arrayList = new ArrayList<>();
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users").child(userId).child("My Players").child("Best Players").child("list");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) dataSnapshot.getValue();
String firstList = (String) map.get("0");
String secondList = (String) map.get("1");
String thirdList = (String) map.get("2");
arrayList.add(firstList + ", " + secondList + ", " + thirdList);
arrayAdapter = new ArrayAdapter<>(this, R.layout.list, arrayList);
listView.setAdapter(arrayAdapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
ref.addListenerForSingleValueEvent(eventListener);
Solution 2:
you can use code given below: change parameters as per your database
databaseReference.child(Table_Dashboard).orderByChild("title").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
spin = new ArrayList<String>();
// spin.add("Dashboard");
for (DataSnapshot spinnerSnapshot : dataSnapshot.getChildren()) {
String areaName = spinnerSnapshot.child("title").getValue(String.class);
spin.add(areaName);
}
// spin.remove("Family Details");
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(Dashboard.this, android.R.layout.simple_spinner_item,
spin);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerAdapter);
dismissprogress();
}
@Override
public void onCancelled(DatabaseError databaseError) {
dismissprogress();
}
});
Post a Comment for "How To Get All Child Node List Values From Firebase Database?"