Android Question Wrong index returned when using the GestureDetector library with CustomListView

Xyloidhead

Member
Licensed User
I've taken the B4A Expandable List demo an attempted to use the GestureDetector library with it. My goal is to use a swipe left to remove an item from the list.

Events are caught but the Sender.Tag field is always the max index. Where as with the normal Panel_Click Sender.Tag is the Index of the element.

So I simply added the GestureDetector under Class Globals
B4X:
Sub Class_Globals
    Private GD As GestureDetector
        --------- rest same --------

I add the listener in the InsertAtImpl
B4X:
Private Sub InsertAtImpl(Index As Int, Pnl As B4XView, ItemHeight As Int, Value As Object, InitialHeight As Int)
    'create another panel to handle the click event
    Dim p As B4XView = CreatePanel("Panel")
    p.Color = Pnl.Color
    Pnl.Color = xui.Color_Transparent
    p.AddView(Pnl, 0, 0, sv.ScrollViewContentWidth, ItemHeight)
    p.Tag = Index
    Log("Initial Index Value: " & p.Tag)
    ' trying to get gestures on the panel
    GD.SetOnGestureListener(p, "Gesture")

And my event handlers
B4X:
Private Sub Gesture_onFling(velocityX As Float, velocityY As Float, MotionEvent1 As Object, MotionEvent2 As Object)
    Dim pnl As B4XView = Sender
    Log("   onFling velocityX = " & velocityX & ", velocityY = " & velocityY & ", ev1 = " & MotionEvent1 & ", ev2 = " & MotionEvent2)
    Log("Item Index: " & pnl.Tag)
End Sub

Private Sub Gesture_onSingleTapConfirmed(X As Float, Y As Float, MotionEvent As Object)
    Dim pnl As B4XView = Sender
    Log("onSingleTapConfirmed Index: " & pnl.Tag)
    PanelClickHandler(Sender)
End Sub

Any help on what I've done wrong would be much appreciated.

Modified B4A Expandable List project included in case the problem is more than just me being dumb.
 

Attachments

  • B4A Expandable List With Gestures.zip
    99.2 KB · Views: 487

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Xyloidhead

Member
Licensed User
Thanks Manfred.

Barely had time to power down my desktop and the phone was indicating I had an answer. And it look like what I'm after. Switched desktop on again so I can give it a try.
 
Upvote 0

Xyloidhead

Member
Licensed User
Looks like it will do what I need, but the code doesn't paste across easily. Will need to invest a little time to understand what changes are needed, which isn't a bad thing.

Will post a version of the Expandable list with swipes when I get it going.

Thanks again for the pointer Manfred.
 
Upvote 0

Xyloidhead

Member
Licensed User
I can confirm it works as I need.

Attached a demo project that does what I needed in case it is of use to anyone.
 

Attachments

  • B4A Expandable List With Swipe.zip
    86.9 KB · Views: 439
Upvote 0

Xyloidhead

Member
Licensed User
Can you tell me in what way it doesn't work? I just downloaded the example code, rather than try my local copy, and it works for me.

Do you have the latest version of the ViewsEx library, it is a requirement of the original swipe example.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Can you tell me in what way it doesn't work?
first there was an error when starting the app, I solved this by setting the customlistview new on the layout "1".
And if i click on a item, then is the swipe down animation the same as without swipe example.
Do you have the latest version of the ViewsEx library, it is a requirement of the original swipe example.
yes i have
 
Upvote 0

Xyloidhead

Member
Licensed User
Not sure what to say. I'd need the error that appeared when you first ran the project. So perhaps trash the current example that you've modified then download it again and this time record what the error is, I can then try and work out what is wrong.

The example behaviour is when started with all the items closed if you swipe down you get the 'Loading' message as per the swipe demo. If you simply touch the triangle the item expands/contracts as in the Expanding list demo. With the items closed if you swipe left across an Item the "Do Something Else" and "Delete" buttons are shown. If you press delete the item is removed, If you press the Do Something Else a log message is generated.

Swiping left while an item works but the two buttons now have a height of the expanded area.

I apologise in advance if it takes me a while to get back to you after any message here. I don't get much time to play.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Swiping left while an item works but the two buttons now have a height of the expanded area.
I thought you changed the animation when you expanded the list.
Because I had expressed a wish and a user had referred me to here.
 
Upvote 0
Top