0

I am trying to populate the chat messages using FirebaseListAdapter.

Below is the code.

 FirebaseListOptions<UserChat> options = new FirebaseListOptions.Builder<UserChat>()
            .setQuery(queryforDisplayMessages, UserChat.class)
            .setLayout(R.layout.chat_user2_item)
            .setLifecycleOwner(this)
            .build();

    final FirebaseListAdapter<UserChat> adapter=new FirebaseListAdapter<UserChat>(
            options
    )       {

        @Override
        protected void populateView(View v, UserChat model, int position) {

            Log.d(TAG,"Inside populateView");
            TextView tv=(TextView)v.findViewById(R.id.textview_message);
            tv.setText(model.getMessage());

        }
    };

    listView.setAdapter(adapter);

I have to differentiate the chat sent and chat received. So in the FirebaseListOptions options I have to use 2 different layouts based on if its a chat sent or chat received. I have a value,called UserModel, in UserChat model class ,from which I can differentiate if its a chat sent or received. But how to use it in the above code and create 2 different FirebaseListOptions ?

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
neab
  • 91
  • 1
  • 3
  • 10

2 Answers2

1

change from listoptions to recycler options this will allow you to create your custom layout everytime using recycler view has more options than list view

sbmalik
  • 464
  • 5
  • 13
1

No, but I'm guessing you're looking for a way to display different views based on the model. This is possible through view types: https://stackoverflow.com/a/26245463/4548500

SUPERCILEX
  • 3,929
  • 4
  • 32
  • 61