When using multiple List Item Type, the recycling view given back to your adapter is wrong type for the asked Type. So it crashes when your code tries to get the viewHolder
It is similar to this issue
http://stackoverflow.com/questions/16526291/listview-with-different-items-and-viewholders-leading-to-classcastexception
When i debugged the code, i found that when offscreen views are added to scrapview List, it was giving wrong ViewType for that view
private void recycleOffscreenViews() {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
System.out.println("######### recycleOffscreenViews child ######### "+child.getTag().getClass().getCanonicalName()+" : "+lp.viewType);
mRecycler.addScrap(child);
}
I checked the viewType obtained from the child LayoutParams. It doesn't have the proper value for that view. It was always 0.
So the problem is, in obtainView() function,
final LayoutParams sglp = (LayoutParams) lp;
sglp.position = position;
sglp.viewType = positionViewType;
// FIX.
view.setLayoutParams(sglp);
The layoutParams is not set to the view. Which is why it is always 0 and while adding to ScrapView list.
So after the setting the LayoutParams to the view before returning the view from obtainView() function, everthing works fine. I had tested with 6 different list items in StaggeredGridView. It handles the recycling of views properly.