我有一个装饰器,我添加到我的recyclerView,并在初始加载和方向更改时装饰器工作得很好。当我删除一个项目时,我希望它根据删除后项目的新位置进行重新装修,但它不起作用。
我尝试添加新装饰器,但失败了;所以现在
我认为在recyclerView上调用类似的东西会强制它重新绘制:它正在执行代码,但背景不会改变。
@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();
}
});
这是我的装饰代码:
@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));}
}
答案 0 :(得分:0)
试试这个,
在list活动的 onResume()方法中设置recyclerview适配器。因此,当对recyclerview进行任何更改时,它将再次设置。
希望这有帮助。