Currently, my RecyclerView adaptor is implementing two different view holders (One for main header, another for hidden child(s)). I got started to implement this type of arrangement from here: http://anandbose.github.io/android_recyclerview_expandablelistview.html
What I want to know is: Prior to the mentioned post, I was inflating layout for the ViewHolder like this:
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_maincategory_one,parent,false);
return new ListHeaderViewHolder(view);
}
Which is a very basic way of doing so. In the mentioned post, the above was implemented something like this:
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater headerInflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = headerInflater.inflate(R.layout.include_expandable_recyclerview_header, parent, false);
return new ListHeaderViewHolder(view);}
I want to know, what is the difference behind the two? Because, the first method doesn't works the way I want to (And the way it's supposed to, in the mentioned post)
Short snippet of implementation (From post):
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = null;
switch (viewType)
{
case CIRCLE_TITLE:
LayoutInflater headerInflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = headerInflater.inflate(R.layout.include_expandable_recyclerview_header, parent, false);
return new ListHeaderViewHolder(view);
case CIRCLE_ADMINS:
LayoutInflater childInflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = childInflater.inflate(R.layout.include_expandable_recyclerview_child,parent,false);
return new ListChildViewHolder(view);
}
return null;
}
Thank You.