Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey, Delphi Android, Delphi IOS

Listview OnItemClick And Swipe To Delete Event Order In Delphi XE6 Firemonkey On Android

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Delphi XE6 Firemonkey Listview Tap Swipe Delete Events | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSDeveloper Jeff Martin has a comment up on Google Plus where he outlines the event order for tapping on a TListView in Delphi XE6 Firemonkey. The original question by John Fisher was basically how to figure out if the Swipe to Delete button is up or not and how to differentiate between that and a normal tap on a TListView item. The answer is only in regards to Android so it may be different on IOS. The answer probably also applies to AppMethod. Here is the full comment from Jeff:
I just ran a test on Android (with only Left/Right enabled in the gesture set for my ListView). Here's what I found:

With no item currently showing a Delete button; a tap on a non-selected ListView item triggers the following events in this order:
* MouseEnter
* Enter
* MouseDown
* Click
* MouseUp
* ItemClick
* Change
* MouseLeave
* ItemClickEx

With no item currently showing a Delete button; a swipe (left or right) gesture on a non-selected ListView item triggers the following events in this order:
* MouseEnter
* Enter
* MouseDown
* DeleteChangeVisible
* ItemClick
* ItemClickEx
<finger held down>
<once lifted...>
* Click
* MouseUp
* MouseLeave
* Gesture

With one item currently showing a Delete button; a tap on a non-selected ListView item triggers the following events in this order:
* MouseEnter
* Enter
* MouseDown
* DeleteChangeVisible
<finger held down>
<once lifted...>
* Click
* MouseUp
* MouseLeave

Other state combinations may produce different results, but I think the key here for your case is that if OnDeleteChangeVisible occurs, it occurs before a Click or ItemClick event. I imagine a parameter of OnDeleteChangeVisible indicates whether or not the button is visible since that event triggers both when the button is becoming visible and when it's becoming invisible.

So, for lack of knowing a better solution, I think setting a flag in an OnDeleteChangeVisible event handler if the Delete button just became visible is a good idea, then perform your desired action, if any, then in the OnItemClick event handler, perform your "click" action only if the flag is clear, and make sure to always clear the flag before exiting the OnItemClick handler so that a true click later is properly handled.
Head over and check out the full question and answer on Google Plus here.

Exit mobile version