0

I usually use ArrayAdapter and i know how to add a new element. Is there any possibility to add a new element into a FirebaseListAdapter? I have created a simple app in which we can add simple messages. Here is my code:

FirebaseListAdapter firebaseListAdapter = new FirebaseListAdapter<Message>(this, Message.class, R.layout.message_text_view, databaseReference) {
        @Override
        protected void populateView(View v, Message message, int position) {
            TextView messageTextView = (TextView) v.findViewById(R.id.message_text_view);
            messageTextView.setText(message.getTextMessage());
        }
    };
    listView = (ListView) findViewById(R.id.list_view);
    listView.setAdapter(firebaseListAdapter);

I also want to add images to the app. All i want to, is to add a new element, which is a ImageView, to the FirebaseListAdapter. The new element i want to be displayed at the end of the ListView. How can i do that?

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • A `FirebaseListAdapter` works with the given `DatabaseReference` or Query. If data is added to that `DatabaseReference`, the `FirebaseListAdapter` receives an update with the newly added data. – Rodrigo Ehlers Jan 11 '17 at 14:16
  • Ok, than the question is, how do i add a new element, which is a `ImageView`, to the my `ListView`? – Alex Mamo Jan 11 '17 at 14:25
  • This wont be possible with a `FirebaseListAdapter` as it only takes one layout. You will have to write your own one or change copy their code and add/modify some lines. – Rodrigo Ehlers Jan 11 '17 at 14:26
  • Ok, i'll try to write my own. But how can i achieve that, do you have any idea? – Alex Mamo Jan 11 '17 at 14:29

1 Answers1

0

Quoting from my own comment on the question:

This wont be possible with a FirebaseListAdapter as it only takes one layout. You will have to write your own one or change copy their code and add/modify some lines.

If you want to change or modify some lines please refer to this answer on another similar question to see what to do to be able to support multiple views inside a single ListAdapter.

Hope this helps!

Community
  • 1
  • 1
Rodrigo Ehlers
  • 1,830
  • 11
  • 25
  • Thank you! This [tutorial](http://android.amberfog.com/?p=296) from this [answer](http://stackoverflow.com/questions/4777272/android-listview-with-different-layouts-for-each-row/4777306#4777306) helped me! – Alex Mamo Jan 11 '17 at 15:44