I am attempting to set a custom span size depending on the type of object that i want to display, however when i am getting the following error in the IDE:
cannot resolve method SetSpanSizeLookup(anonymous.android.support.v7.widget.GridLayoutManager.SpanSizeLookup)
I can't figure out why this is as it appears to be a supported method according to google
mLayoutManager = new GridLayoutManager(this,3);
mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
switch(mAdapter.getItemViewType(position)){
case MyAdapter.TYPE_HEADER:
return 2;
case MyAdapter.TYPE_ITEM:
return 1;
default:
return -1;
}
}
});
Your mLayoutManager object must of be of type GridLayoutManager.
In the case where you need it to be of the abstract type LayoutManager (even though I cannot envision such a case), you can cast it as follows:
((GridLayoutManager) mLayoutManager).setSpanSizeLookup(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With