My FireBase DataBase is like this:
I want to get all the values from groupname as a String List or any form of list and use it to populate a Spinner. The problem I am getting is that it doesn't retrieve any value . This is my actual code:
@Override
protected void onStart() {
super.onStart();
databaseGroups.child("Groups").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
final List<String> areas = new ArrayList<String>();
for (DataSnapshot areaSnapshot: dataSnapshot.getChildren()) {
String areaName = areaSnapshot.child("groupname").getValue(String.class);
areas.add(areaName);
System.out.println("Group Names are ::::::::::::::::::::::"+areas);
}
// Spinner element
Spinner spinner = (Spinner) findViewById(R.id.spinner);
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(member_auth.this, android.R.layout.simple_spinner_item, areas);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
The Spinner is empty, plse help...