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 ?
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