我为我的回收者视图设置了一个带有FirebaseRecyclerAdapter的Itemtouchhelper。对于我的recyclerview行,我有2个布局,一个在前面,一个在后面。当我滑动该行时,顶部将移动而离开底部视图。问题是当它删除该行时,然后添加了另一个项目,该视图仅显示布局的背面,而不是旧删除项所在位置的正面,
我厌倦了在线找到的解决方案,该解决方案是从recyclerview中删除itemTouchHelper,然后再次添加它,并将更改通知我的适配器。
这是我的代码
ItemTouchHelper.SimpleCallback itemTouchHelpCallBack = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
View foregroundView = viewHolder.itemView.findViewById(R.id.foregroundView);
getDefaultUIUtil().onDraw(c, recyclerView, foregroundView, dX, dY, actionState, isCurrentlyActive);
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
cartAdapter.getRef(viewHolder.getAdapterPosition()).removeValue();
list.remove(viewHolder.getAdapterPosition());
totalPrice.setText(getResources().getString(R.string.totalPrice, String.valueOf(TotalPriceCalc(list))));
}
答案 0 :(得分:0)
我找到了解决方法,
我想念
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
View foregroundView = viewHolder.itemView.findViewById(R.id.foregroundView);
getDefaultUIUtil().clearView(foregroundView);
}