Skip to content Skip to sidebar Skip to footer

How To Use ExpandableRecyclerView Library With Multiple (child) ViewTypes?

I need an Activity with an expandable RecyclerView like the one in this picture: So I am using this third party library project . That part works. The problem arose when I did wha

Solution 1:

By comparing Line#13 of this stack-trace of the error free program, and this one of the program which results in the exception, and by looking at the onCreateViewHolder(ViewGroup viewGroup, int viewType) method definition on Line#117 of this ExpandableRecyclerAdapter.java class, from which I infer that onCreateViewHolder is being passed the wrong viewType parameter.

But I haven't yet been able to figure out why!


I think I have figured it out.

Actually the trick of TYPE_SOMETHING constants that I am using in MyExpandableRecyclerAdapter is the same one they have used in ExpandableRecyclerAdapter, i.e. in my MyExpandableRecyclerAdapter, 0 is the value of TYPE_EDITTEXT and 1 is the value of TYPE_SPINNER; whereas in their ExpandableRecyclerAdapter, which is extended by my MyExpandableRecyclerAdapter, 0 is the value of TYPE_PARENT and 1 is the value of TYPE_CHILD.

If the Android framework passes the same viewType parameter to onCreateViewHolder which is returned from getItemViewType(int position), it will pass 1 if it was TYPE_SPINNER in my MyExpandableRecyclerAdapter, but their ExpandableRecyclerAdapter will understand it as TYPE_CHILD, and thus call onCreateChildViewHolder.

So I think the whole thing I am trying to achieve can't be done. =(


Post a Comment for "How To Use ExpandableRecyclerView Library With Multiple (child) ViewTypes?"