I have a basic custom View which looks like this:
public class CustomView extends RelativeLayout {
private User user;
private ImageView profilePict
CustomView extends RelativeLayout {
You have a View already (well, a ViewGroup
)
HOW TO INFLATE THE CUSTOM VIEW?
You don't need to... The point of a Custom View object is to not need XML, therefore no inflation.
You can create new CustomView()
, but you need to set all the layout parameters, which looks cleaner in XML, I think.
Most RecyclerView
tutorials show inflating via XML though.
View customView = inflater.inflate(...); ViewHolder viewHolder = new ViewHolder(customView);
That should work because in the class chain, you have CustomView > RelativeLayout > ViewGroup > View
LayoutInflater inflater = LayoutInflater.from(context);
Like I said before, you don't need this if there is no XML file you want to inflate.
You also don't need the context
variable.
parent.getContext()
is a fine solution.
// ANYTHING HERE?
Well, yeah, you should "bind" the ViewHolder
with the data that the ViewHolder
should hold.
Again, most, if not all, tutorials cover this.