daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

BaseSwipeAdapter unchecks ListViewItems in MultiChoiceMode #383

Open gw212 opened 8 years ago

gw212 commented 8 years ago

I have a ListView that allows users to select multiple items in the ListView by registering a MultiChoiceMode listener on the ListView. I have since added the BaseSwipeAdapter to my project for this ListView, but now when you hold down on an item to select it, the item gets selected with the MultiChoiceMode menu appearing for a second before it gets deselected. If I move my finger down slightly, as if I'm swiping down just a bit (moving it maybe a few millimeters on my phone), the menu stays open and I can select multiple items in the ListView. Also interesting enough, if I set a debug point on my onItemCheckedStateChanged() method, it prevents the item from being deselected as well.

gw212 commented 8 years ago

Some more information on what I see happening: This is the thread dump I'm getting before my ListView's onItemCheckedStateChanged listener method gets called: at android.widget.AbsListView$MultiChoiceModeWrapper.onItemCheckedStateChanged(AbsListView.java:8561) at android.widget.AbsListView.performItemClick(AbsListView.java:1520) at android.widget.AbsListView$PerformClick.run(AbsListView.java:3822) at android.widget.AbsListView$3.run(AbsListView.java:5844) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7225) at java.lang.reflect.Method.invoke(Method.java:-1) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

So best I can see, there's a call to simulate the ListView's onClick method which is acting as a click (possibly outside the ListView) to deselect the items.

shailendrapundhir commented 8 years ago

This might happen if your list has multiple methods for handling touch events. (For ex onClick and onSwipe /onTouch) . So to resolve your issue you might move your touch handling to any one method (probably the onSwipe /onTouch one). Also make sure you save the state of every item(whether it is selected or not)somewhere and use it to set the state of item everytime the list refreshes / scrolls. I think these two should be able to resolve your issues.

gw212 commented 8 years ago

I only have 2 events for the ListView, an onItemClickListener and a multiChoiceModeListener, where the onItemClickListener is never actually called when I'm holding down on a row to activate the Multi Choice mode. The SwipeLayout used for the ListView rows has a SwipeListener that I've only been using for testing this out but is otherwise doing nothing.

So I don't think the issue is the multiple touch event methods, at least not through any methods I have for handling them. And I am keeping the state of the selected items, but the issue is the immediate call to onItemCheckedStateChanged to uncheck the selected item and causing it to be removed from the Set I'm maintaining to keep track of the states.