0

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 database tree

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();
    }
}
5
  • @Frank van Puffelen is my qestion hard to understand? Should I explain in some other way? Commented Jul 19, 2016 at 12:37
  • @Frank I have added code now that get the name from my Object but how do I pass multiple things to my custom listview layout. Check the update. Commented Jul 20, 2016 at 19:07
  • "and the childs...will be additional information for each listitem". Where will the information be displayed? On the list item itself or in an activity that opens when the list item is clicked? Commented Jul 20, 2016 at 19:16
  • @quidproquo The information will be displayed on the list item itself. Commented Jul 20, 2016 at 19:21
  • @quidproquo Now textView2 get the name and what I want to do is add value of nature to another textView in the same layout Commented Jul 20, 2016 at 19:28

1 Answer 1

1

You've to use Cardview layout instead of a Listview.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.