NotifyItemChanged not a refreshing look

First of all, I worked on this all day, but could not do anything. I have a RecyclerView with an adapter that uses a RecyclerView SortedList . I tried implementing TouchHelper with a callback class:

 public class TimerListTouchHelperCallback extends ItemTouchHelper.SimpleCallback { private OnItemChangeListener onItemChangeListener; public TimerListTouchHelperCallback(OnItemChangeListener listener, int dragDirs, int swipeDirs) { super(dragDirs, swipeDirs); this.onItemChangeListener = listener; } @Override public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { TimerHolder holder = (TimerHolder) viewHolder; int holderState = holder.getState(); if (holderState == TimerHolder.TIMER_PENDING_DELETE) return 0; else return super.getSwipeDirs(recyclerView, viewHolder); } @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) { TimerHolder holder = (TimerHolder) viewHolder; int position = holder.getAdapterPosition(); // ViewHolder state is changed that should handle the layout change. holder.setState(TimerHolder.TIMER_PENDING_DELETE); if (onItemChangeListener != null) onItemChangeListener.onItemSwiped(position); } protected interface OnItemChangeListener{ void onItemSwiped(int position); } } 

Here is the initialization of TouchHelper

 timerAdapter = new TimerAdapter(this, timerList); timerListView.setAdapter(timerAdapter); TimerListTouchHelperCallback touchHelperCallback = new TimerListTouchHelperCallback( timerAdapter, ItemTouchHelper.LEFT, ItemTouchHelper.LEFT); ItemTouchHelper swipeToDismissTouchHelper = new ItemTouchHelper(touchHelperCallback); swipeToDismissTouchHelper.attachToRecyclerView(timerListView); 

My adapter implements the OnItemChangeListener interface

 @Override public void onItemSwiped(int position) { notifyItemChanged(position); removalPendingTimers.add(timerList.get(position)); } 

My ViewHolder reads the state, and when the state is TimerHolder.TIMER_PENDING_DELETE , it hides the rest of the view and shows the interface using the cancel button. But this does not happen until I scroll the view and scroll it back. Any suggestions that I am missing?

Problem

References

Adapter class ViewHolder class

+5
source share
2 answers

I created a simple example Android application to better understand the issue.

It uses notifyItemChanged (position); when the user scrolls the item left or right to display the undo view. When the undo time expires, it calls notifyItemRemoved (position) to remove it from the list. See For example, GIF does not leave blank lines.

https://github.com/DawidvanGraan/ExampleRecycleViewSwipeDismiss

+1
source

It is finally up and running. Since notifyItemChanged did not cut (which should be), I used notifyItemRemoved , and then notifyItemInserted .

Somewhat behind, but it works.

+1
source

All Articles