Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridLayoutManager setSpanCount not working in OnClickListener of a button

Well, I want to change the span count of recycler view Grid layout manager's dynamically on 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 on OnCreate in activity

it changes the gridSpanCount in the recyclerView.

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

like image 576
mudit_sen Avatar asked Sep 18 '15 07:09

mudit_sen


1 Answers

Just call adapter's notifyDataSetChanged() after setting new span count value.

like image 80
sergej shafarenka Avatar answered Nov 09 '22 04:11

sergej shafarenka