GridLayoutManager setSpanCount does not work in OnClickListener buttons

Well, I want the dynamic dynamic markup of the recycler list to be displayed dynamically with the click of a button.

    GridLayoutManager manager;

    @Override
    public void onClick(View v) {


        if(manager.getSpanCount() > 16)
        {
            manager.setSpanCount(1);
        }
        manager.setSpanCount( manager.getSpanCount()+1);

        mRecyclerView.setLayoutManager(manager);
    }

but when I try to change it to OnCreate in action

it changes gridSpanCount to recyclerView.

Please tell me how to fix it. and it also does not work in onTouchListener on the view.

+4
source share
2 answers

Just configure the adapter notifyDataSetChanged()after setting a new counter value.

+5
source

Here I am inserting my piece of code, not what you want, but maybe you will get any hint.

 mLayoutManager = new GridLayoutManager(getActivity(), MAX_COLUMNS);



        mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if (position == MAX_COLUMNS) {
                    return (firstDayofWeek - 1);
                } else {
                    return 1;
                }


            }
        });

    mRecyclerView.setLayoutManager(mLayoutManager);
0
source

Source: https://habr.com/ru/post/1607966/


All Articles