I am trying to develop a quiz app in which sometimes questions have and image in the question is it possible to design two different single element view of recyclerview (one with image and other without image) and bind it to recycler view according to need.
Asked
Active
Viewed 54 times
1 Answers
0
In your oncreate viewholder based on position inflate the view like below
private Context context;
private List<MenuListItem>menuListItemList;
private int position;
public MenuItemsAdapter(Context context, List<MenuListItem>
menuListItemList, int position) {
this.context = context;
this.menuListItemList = menuListItemList;
this.position = position;
}
@NonNull
@Override
public MenuItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view;
if (position==0){
view = LayoutInflater.from(context).inflate(R.layout.first_row_grid_item,parent,false);
}
else {
view = LayoutInflater.from(context).inflate(R.layout.menu_items,parent,false);
}
return new MenuItemViewHolder(view);
}

Wahdat Jan
- 3,988
- 3
- 21
- 46