This's my code in onCreateViewHolder
@Override
public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
ViewGroup viewGroup = (ViewGroup) LayoutInflater.from(parent.getContext()).inflate(R.layout.widget_holder, parent, false);
if (CAT_IMAGE_IDS.get(i).getButton()) {
LinearLayout ln = new LinearLayout(parent.getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(230, 250, Gravity.CENTER);
ln.setLayoutParams(params);
viewGroup.addView(ln);
i++;
return new ItemViewHolder(viewGroup);
} else if (CAT_IMAGE_IDS.get(i).getDummy()) {
LinearLayout ln = new LinearLayout(parent.getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(230, 250, Gravity.CENTER);
ln.setLayoutParams(params);
viewGroup.setVisibility(View.INVISIBLE);
viewGroup.addView(ln);
i++;
return new ItemViewHolder(viewGroup);
}
I've been told it's not a good practice to write it there, and it should be inside onBindViewHolder.
I can't seem to figure out how to do it properly even though I took a look at some examples online.
So how should I go about this?