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?
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.
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.
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.
You could do it like this:
while (recyclerView.getItemDecorationCount() > 0) {
recyclerView.removeItemDecorationAt(0);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With