Reputation: 1
In this format i have databse in firebase.I have to display all the departments in the form of array list like Director,sports.
mAuth=FirebaseAuth.getInstance();
mdatabase=FirebaseDatabase.getInstance().getReference().child("Department";
mdatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
List<String> Department = (ArrayList<String>) dataSnapshot.getValue();
DepartmentLIST=Department.toArray(new String[Department.size()]);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(CheckUpdate.this,databaseError.getMessage(),Toast.LENGTH_LONG).show();
}
});
setListAdapter(new ArrayAdapter(this,
android.R.layout.simple_list_item_1,DepartmentLIST));
}
This is my code i have used for it. But it gives NullValue.
Upvotes: 0
Views: 97
Reputation: 191701
(ArrayList<String>) dataSnapshot.getValue()
isn't correct.
I think you are looking for dataSnapshot.getChildren()
, and / or dataSnapshot.getValue(String.class)
.
Note: Firebase-UI library could help you here.
Upvotes: 1