Ответ 1
Ранее я работал над подобной проблемой, но я настроил RecyclerView Adapter вручную, я не использовал для этого никакой библиотеки. Я даю вам образец кода здесь. Это полный адаптер типа Multile View Type
public class UserPostAdapter extends RecyclerView.Adapter<UserPostAdapter.PostViewHolder> {
private List<UserPostsListItem> postlist;
Context conetxt;
LayoutInflater inflater;
private ViewClickListener mClickListener;
private ItemViewClickListener itemViewClickListener;
int count;
public UserPostAdapter() {
}
public UserPostAdapter(Context conetxt, List<UserPostsListItem> postlist) {
this.postlist = postlist;
this.conetxt = conetxt;
inflater = LayoutInflater.from(this.conetxt);
}
@Override
public int getItemCount() {
int size = 0;
if (postlist != null)
size = postlist.size();
return size;
}
@Override
public int getItemViewType(int position) {
int viewTypePosition =0;
String attachment_type = postlist.get(position).getAttachment_type();
switch (attachment_type){
case "text":
viewTypePosition = 0 ;
break;
case "image":
viewTypePosition = 1 ;
break;
case "audio":
viewTypePosition = 2 ;
break;
case "video":
viewTypePosition = 3 ;
break;
default:
}
return viewTypePosition;
}
@Override
public void onBindViewHolder(final PostViewHolder videoViewHolder, final int position) {
//Log.d("onBindViewHolder",Integer.toString(position));
final UserPostsListItem item = postlist.get(position);
switch (item.getAttachment_type()){
case "audio":
break;
case "video":
break;
case "text":
break;
case "image":
break;
default:
}
}catch (Exception e){
e.printStackTrace();
}
}
public interface ItemViewClickListener {
void onItemChildClicked(int position ,String type);
}
public void setItemViewClickListener (ItemViewClickListener viewClickListener) {
itemViewClickListener = viewClickListener;
}
public List<UserPostsListItem> getUserPostsList() {
return postlist;
}
@Override
public PostViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType){
Log.d("ViewType", Integer.toString(viewType));
switch (viewType) {
case 0:
View itemViewText = inflater.inflate(R.layout.userposts_listitem_text, viewGroup, false);
return new PostViewHolder(itemViewText ,viewType);
case 1:
View itemViewTextImage = inflater.inflate(R.layout.userposts_listitem_textandimage, viewGroup, false);
return new PostViewHolder(itemViewTextImage,viewType);
case 2:
View itemViewTextAudio = inflater.inflate(R.layout.userposts_listitem_audioandtext, viewGroup, false);
return new PostViewHolder(itemViewTextAudio,viewType);
case 3:
View itemViewTextVideo = inflater.inflate(R.layout.userposts_listitem_videoandtext, viewGroup, false);
return new PostViewHolder(itemViewTextVideo,viewType);
default:
}
return null;
}
public interface ViewClickListener {
void onVideoClicked(int position,View v);
}
public List<UserPostsListItem> getVideoItems() {
return postlist;
}
public void setViewClickListener (ViewClickListener viewClickListener) {
mClickListener = viewClickListener;
}
public static class PostViewHolder extends RecyclerView.ViewHolder {
ImageView attachment;
CircleImageView circleImageView;
ImageView audio;
public PostViewHolder(View v,int viewtype) {
super(v);
switch (viewtype){
//For Audio
case 2:
break;
//For Video
case 3:
break;
//For Text only
case 0:
break;
//For Image
case 1:
break;
default:
}
}
}
}