Android recyclerview remove all item decorators

I did this:

dividerItemDecoration = new DividerItemDecoration(
        recyclerView.getContext(),
        DividerItemDecoration.VERTICAL
    );
recyclerView.addItemDecoration(dividerItemDecoration);

      

Then I change the orientation of the devices, so now I don't have this dividerItemDecoration and I want to remove the divider from the recyclerView. Is it possible?

+3


source to share


2 answers


To remove ItemDecoration you need to use removeItemDecoration . For your case, the code would be:



recyclerView.removeItemDecoration(dividerItemDecoration);

      

+7


source


You can do it like this:



while (recyclerView.getItemDecorationCount() > 0) {
    recyclerView.removeItemDecorationAt(0);
}

      

+1


source







All Articles