Skip to content Skip to sidebar Skip to footer

Create Views Programmatically In A Recyclerview.viewholder And Passing Arguments To It

Can I create views programmatically in a ViewHolder instead of binding them from XML in the classic way as in all examples? Also, my views need an image filepath in order to be cre

Solution 1:

Did u try create View itemView via code?

for ex.:

ll = newLinearLayout(this);
ll.setOrientation(android.widget.LinearLayout.VERTICAL);
ll.setLayoutParams(new ViewGroup.LayoutParams(-1,-1));
ll.setBackgroundColor(0x88ff0000);

tv = newTextView(this);
tv.setLayoutParams(new ViewGroup.LayoutParams(-1,-2));
tv.setText("sample text goes here");
tv.setBackgroundColor(0x5500ff00);
ll.addView(tv);

and

ImagePreviewViewHolderholder=newImagePreviewViewHolder(ll);

Post a Comment for "Create Views Programmatically In A Recyclerview.viewholder And Passing Arguments To It"