I just make a chat application with Firebase and using RecyclerView in XML and using FirebaseRecyclerAdapter in Android, but the problem is that when I send a message throug
public Class MyAdapter extends FirebaseRecyclerAdapter<ModelClass, ViewHolderClass> {
private static final int LAYOUT_ONE = 1;
public MyAdapter(Class<ModelClass> modelClass,
int modelLayout,
Class<ViewHolderClass> viewHolderClass,
Query ref) {
super(modelClass, modelLayout, viewHolderClass, ref);
}
@Override
public ViewHolderClass onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
if (viewType == LAYOUT_ONE) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_one, parent, false);
return new ViewHoldeClassr(view);
}
else {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_two, parent, false);
return new ViewHolderClass(view);
}
}
@Override
public int getItemViewType(int position)
ModelClass model = getItem(position);
if (model.caseWhenYouWentToUseLayoutOne)) {
return LAYOUT_ONE;
}
return position;
}
}
The FirebaseUI adapters were made for a homogenous lists with a single layout. While having heterogenous list with multiple layouts were always considered an interesting feature to add (see this original feature request), it hasn't been added so far.
There is an open feature request for specifically adding multi-layout support on the FirebaseUI library: https://github.com/firebase/FirebaseUI-Android/issues/305.
You might want to add your vote/+1 to that.