How To Read Childrens From A Firebase Database Using Firebaselistadapter In Java?
I am very new in Firebase. So, i have a database structure like this: and want to display those generated id's into a listview. I'm using FirebaseListAdapter. Here is my code:
Solution 1:
Change the populateView
method implementation to
firebaseListAdapter = newFirebaseListAdapter<User>(this, User.class, android.R.layout.simple_list_item_1, databaseReference) {
@OverrideprotectedvoidpopulateView(View v, User user, int position) {
TextViewtextView= (TextView) v.findViewById(android.R.id.text1);
StringuserKey=this.getRef(position).getKey();
textView.setText(userKey);
}
};
Solution 2:
You'll need a FirebaseListAdapter<Map>
instead of FirebaseListAdapter<String>
. Your code would become something like this (didn't compile it though, that's up to you ;-)
databaseReference = FirebaseDatabase.getInstance().getReference().child("Firebase").child("Users");
firebaseListAdapter = newFirebaseListAdapter<Map>(this, Map.class, android.R.layout.simple_list_item_1, databaseReference) {
@OverrideprotectedvoidpopulateView(View v, Map users, int position) {
TextView textView = (TextView) v.findViewById(android.R.id.text1);
textView.setText(users.getKey());
}
};
listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(firebaseListAdapter);
Post a Comment for "How To Read Childrens From A Firebase Database Using Firebaselistadapter In Java?"