So, I\'m facing a weird problem while implementing RecyclerView in my project. I have a custom decorator to implement a consistent top and bottom padding and a rather different
You have to remove the item decoration before reseting new data.
rv.removeItemDecoration(yourDecorator)
Let me know if it works!
I had the same issue and I fixed that with the itemDecorationCount
if (recyclerView.itemDecorationCount == 0) {
val itemDecorator = DividerItemDecoration(activity, DividerItemDecoration.VERTICAL)
itemDecorator.setDrawable(ContextCompat.getDrawable(activity, R.drawable.recycler_divider))
recyclerView.addItemDecoration(itemDecorator)
}
You are adding Decoration
each time recyclerview is loaded.
Use one flag instead :
private boolean flagDecoration = false;
if(!flagDecoration)
{
rv.addItemDecoration(new RecyclerViewItemDecoration(30, item_count - 1));
flagDecoration = true;
}
Faced the same issue and resolved it by placing
mLayoutManager = new LinearLayoutManager(current_activity);
recyclerView.setLayoutManager(mLayoutManager);
in onPreExecute()
method.
Just give it a try if it works
I face the same issue. Fix it with if check
if (recyclerView.getItemDecorationAt(0) == null) { // check decoration here
FlexboxItemDecoration agentDividerItemDecoration = new FlexboxItemDecoration(rv.getContext());
agentDividerItemDecoration.setDrawable(recyclerView.getContext().getResources().getDrawable(R.drawable.shape_divider_flex_normal));
recyclerView.addItemDecoration(agentDividerItemDecoration);
} else {
Log.i(TAG, "initTagsView: ItemDecoration not null");
}
I was facing the same issue, the best solution is to make your item decoration while your are initializing your layout manager in the view holder , this resolves the problem you are facing example
public class GridViewHolder extends ViewHolder {
RecyclerView grid_list;
public GridViewHolder(View v) {
super(v);
this.grid_list = (RecyclerView) v.findViewById(R.id.home_screen_item_grid_recycler_view);
if (grid_list.getLayoutManager() == null) {
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(context, 4);
grid_list.setLayoutManager(mLayoutManager);
grid_list.addItemDecoration(new GridSpacingItemDecoration(4, 3, false));
}
}
}