I have a decorator that I Added to my recyclerView, and on the initial load and when orientation changes the decorator works great. When I remove an item I want it to redecorate based on the new positions of the items after the delete but it is not working.
I have tried adding new decorators, that failed; so now
I thought that calling something like on the recyclerView would force it to re draw: it is executing the code but the background does not change.
@Override
public void onItemRangeChanged(int positionStart, int
itemCount) {
super.onItemRangeChanged(positionStart, itemCount);
Log.e(TAG, "range start: " + positionStart + " count: " +
itemCount );
Runnable pendingRemovalRunnable = new Runnable() {
@Override
public void run() {
mRecyclerView.invalidateItemDecorations();
Log.d(TAG, "run");
}
};
pendingRemovalRunnable.run();
}
});
This is my decorator code:
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView
parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
int pos = parent.getChildAdapterPosition(view);
if (pos == -1)
return;
String vid = ((RVAdapter)parent.getAdapter()).getVid(pos);
mIsInlist =
PlaylistManager.get(view.getContext()).getIsInPlaylist(vid);
mIsTop = PlaylistManager.get(view.getContext()).getIsTop(vid);
mIsBottom = PlaylistManager.get(view.getContext()).getIsBottom(vid);
mRegularLayout = (LinearLayout)
view.findViewById(R.id.regularLayout);
if (mIsInlist) {
if (mIsTop) {
mRegularLayout.setBackground(ContextCompat
.getDrawable(view.getContext(),
R.drawable.list_selector_playlist_top));
} else { if (mIsBottom) {
mRegularLayout.setBackground(ContextCompat.
getDrawable(view.getContext(),
R.drawable.list_selector_playlist_bottom));
} else {
mRegularLayout.setBackground(
ContextCompat.getDrawable(view.getContext(),
R.drawable.list_selector_playlist)); }
} else {
mRegularLayout.setBackground(ContextCompat.
getDrawable(view.getContext(), R.drawable.list_selector));}
}