Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot resolve setSpanSizeLookup for gridviewlayoutmanager

Tags:

java

android

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;
        }
    }
});
like image 966
PowerMan2015 Avatar asked Mar 01 '26 00:03

PowerMan2015


1 Answers

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(...)
like image 150
johnsky Avatar answered Mar 02 '26 15:03

johnsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!