I want to add an whole object to my listview using Firebase. Have been illustration this with a image because sometimes an image is just easier than text.
Firebase tutorials show how to return each child as an item and display it with Firebase UI and I want to almost do the same thing but the difference is that I want the whole object to be the child and the childs inside that object will be additional information for each listitem.
So in my image I have object Camping and the "Mountains", "Nature", "Place". In an custom listView I want the different values be set to textViews.to be the
This is how I get the child items with the Firebase UI:
protected void onStart(){
super.onStart();
Firebase items = rootRef.child("events");
final FirebaseListAdapter<String> fireAdapter = new FirebaseListAdapter<String>(
this,String.class,R.layout.list_item,items) {
@Override
protected void populateView(View view, String s, int i) {
TextView testText = (TextView)view.findViewById(R.id.textView2);
testText.setText(s);
trucks.add(s);
}
};
listView.setAdapter(fireAdapter);
}
UPDATE
Here is code how I get mountains value to be set to a textview in my custom listview layout:
private void getUpdatesEvents(DataSnapshot dataSnapshotRoot){
events.clear();
for(DataSnapshot dataSnapshot : dataSnapshotRoot.getChildren()){
Events e = new Events();
e.setName(dataSnapshot.getValue(Events.class).getName());
events.add(e.getName());
}
if(events.size()>0){
ArrayAdapter adapter = new ArrayAdapter(this,R.layout.list_item,R.id.textView2,events);
listView.setAdapter(adapter);
}
else{
Toast.makeText(this,"There is no data",Toast.LENGTH_LONG).show();
}
}
