Open jayhack7 opened 8 years ago
@pcodemang I've just checked again, it should delete all items that have been swiped away (say e.g. the first three items all at once). Can you specify the system you are testing this on.
The swipe delay can't be customized currently, you can track progress in issue #12.
@TR4Android Yeah, I double checked the sample and realized I must have messed up somewhere. Perhaps I am going about the wrong way of deleting items? I am using Genymotion emulator Nexus 5, API 23 on 5.1 https://gist.github.com/pcodemang/a8a96a5c5bb7713dfb6bd1e22c80d97f Line 126 - Here is the specific method I use for deleting items. ShotsModel is a SQL table.
`public void deleteItems (int position, int direction){ try{ final ShotsModel shot = shots.remove(position); //shots.remove(position);
shot.delete();
notifyItemRemoved(position);
notifyDataSetChanged();
} catch (IndexOutOfBoundsException e){
notifyDataSetChanged();
e.printStackTrace();
}
Toast toast = Toast.makeText(context, "Deleted item at position " + position, Toast.LENGTH_SHORT);
toast.show();
}`
OK, I believe I found a partial solution. I commented out //shots.remove(position); When I put it back in, I can now multi-delete entries, although it only works if the user takes a second between each swipe. AT this point, I believe the problem is coming from the way I am calling my database in the fragment that the adapter is called in
You might want to try something similiar to this (no guarantees though):
public void deleteItems (int position, int direction) {
final ShotsModel shot = shots.remove(position);
notifyItemRemoved(position);
// delete the shot from the database
shot.delete();
}
There's no need to call notifyDataSetChanged
if you're using notifyItemRemoved
, in fact it will make the adapter loose the knowledge about any pending swipes (i.e. items that are in countdown) as it cannot keep track of the dataset.
@TR4Android The reason I keep notifyDataSetChanged
is that this error appears as I attempt to delete items without it.
09-27 15:48:35.764 16191-16191/com.slifers.dailyfreethrowtracker E/AndroidRuntime: FATAL EXCEPTION: main Process: com.slifers.dailyfreethrowtracker, PID: 16191 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{a7ed489 position=2 id=-1, oldPos=3, pLpos:3 scrap [attachedScrap] tmpDetached no parent} at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4858) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4989) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4970) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578) at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3266) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3122) at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1549) at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:305) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:549) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Is there any solution please ?
Thank you for the library.
If I try to to swipe multiple entries without waiting for the 5 second undo "cooldown", it only deletes the first entry that was swiped. Is there a better way to handle this other than reducing the time?