I'm basically trying to get the values of Key "name" from Firebase then show all the names into a listview. The problem is that my data from Firebase doesn't shows up in the listView even though my code is having no errors.
Firebase Structure: MY FIREBASE DATABASE STRUCTURE
My Code:
List<String> list = new ArrayList<>();
list.addAll(FFunc());
Toast.makeText(this, "Success!", Toast.LENGTH_SHORT).show();
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.activity_listview, R.id.textView, list);
simpleListView.setAdapter(arrayAdapter);
public List<String> FFunc(){
final List<String> arr = new ArrayList<>();
DatabaseReference database = FirebaseDatabase.getInstance().getReference("Employee");
DatabaseReference myRef = database.child("name");
myRef.addValueEventListener(new com.google.firebase.database.ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot data : dataSnapshot.getChildren()) {
String name = data.getValue(String.class).toString();
arr.add(name);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
});
return arr;
}
By using the above code, I'm getting an empty listView with no values from Firebase. Anyone can tell me what's can be the possible solution to this problem. I'm a Beginner in Android thus I have no idea what to do next even after spending 2 whole days on it.