I want to populate my expandable list view with the values from Firebase database. I am able to add data to views statically but through Firebase not.
This is my code for that:
public class ExpandableListitems {
public List<String> food;
public HashMap<String, List<String>> getData() {
final HashMap<String, List<String>> expandableListDetail = new HashMap<String, List<String>>();
//getting fooditems from database
FirebaseDatabase firebaseDatabasefighter = FirebaseDatabase.getInstance();
DatabaseReference databaseReferencefighter = firebaseDatabasefighter.getReference("food").child("food_details");
ValueEventListener valueEventListenerfighter = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
food = new ArrayList<String>();
String value = String.valueOf(ds.getValue());
food.add(value);
Log.i("vipan",value);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
};
databaseReferencefighter.addValueEventListener(valueEventListenerfighter);
food.add("milk");
food.add("dahi");
food.add("paratha");
food.add("aaloo");
expandableListDetail.put("FoodItems", food);
return expandableListDetail;
And my database looks like this:
food
food_details: "2% Fat Milk"
i want to add this food_details value into the listview's view but unable so far.How can i implement this?