Here is my onBindViewHolder:
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
MessageModel message = values.get(position);
switch (holder.getItemViewType()) {
case VIEW_TYPE_VIDEO_SENT:
((VideoMessageHolder) holder).sentBinding.setMessageModel(message);
break;
case VIEW_TYPE_VIDEO_RECEIVED:
((VideoMessageHolder) holder).receivedBinding.setMessageModel(message);
break;
}
}
Here is my ViewHolder:
private class VideoMessageHolder extends RecyclerView.ViewHolder {
private RowRecyclerViewChatVideoMessageSentBinding sentBinding;
private RowRecyclerViewChatVideoMessageReceivedBinding receivedBinding;
VideoMessageHolder(RowRecyclerViewChatVideoMessageSentBinding binding) {
super(binding.getRoot());
this.sentBinding = binding;
}
VideoMessageHolder(RowRecyclerViewChatVideoMessageReceivedBinding binding) {
super(binding.getRoot());
this.receivedBinding = binding;
}
}
I want to be able to get appropriate binding to be able to make changes to the views inside.
When you have 2 different layout for recyclerview than you must have 2 different viewholder for it.
First add 2 different viewHolder for your adapter
after that set item type for adapter with this method
in your
onCreateViewHolder
use 2 viewHolder like this:and inside your onBindViewHolder you can call eash viewHolder method: