Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android recyclerview remove all item decorators

I did this:

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

Then i change devices orientation, so now i dont have that dividerItemDecoration, and i want to delete divider from recyclerView. Is it possible?

like image 928
Ivan Salosin Avatar asked Jun 11 '17 05:06

Ivan Salosin


People also ask

How to remove item Decoration from RecyclerView in android?

Here's the Kotlin extension function I created to remove all of a recyclerView's item decorations. Don't forget to import <path to extensions file>. _KotlinExtensions. removeItemDecorations at the top of whatever class you plan to use the extension function in.

What is Item decoration in RecyclerView?

An ItemDecoration allows the application to add a special drawing and layout offset to specific item views from the adapter's data set. This can be useful for drawing dividers between items, highlights, visual grouping boundaries and more.

Which method must be overridden to implement a RecyclerView?

RecyclerView includes a new kind of adapter. It's a similar approach to the ones you already used, but with some peculiarities, such as a required ViewHolder . You will have to override two main methods: one to inflate the view and its view holder, and another one to bind data to the view.


1 Answers

You could do it like this:

while (recyclerView.getItemDecorationCount() > 0) {
    recyclerView.removeItemDecorationAt(0);
}
like image 52
Szymon Chaber Avatar answered Oct 14 '22 07:10

Szymon Chaber