Help with error - CustomListview with touch events

tunderin

Member
Licensed User
Longtime User
Hi,

My app includes an activity with slidingPanels, there are 4 of them.

The panels contain standard listviews and customListviews. The code below adds touch listeners so that swiping over the listview will cause the panel to slide

B4X:
'listviews do not have events & properties needed to recognize a swipe
'wrap listviews with touch listeners to handle swipes over listviews
Dim r1,r1b,r2,r3,r4 As Reflector
   
r1.Target = lv1
r1.SetOnTouchListener("Listview_Touch")
   
r1b.Target = lv1b
r1b.SetOnTouchListener("Listview_Touch")
   
r2.Target = clvs1
r2.SetOnTouchListener("Listview_Touch")
   
r3.Target = clvs2
r3.SetOnTouchListener("Listview_Touch")
   
r4.Target = lv4 
r4.SetOnTouchListener("Listview_Touch")

Everything works properly with the standard listviews but When the r2 & r3 reflectors are added for the customListviews, the following error occurs at runtime:

B4X:
claimdetails_activity_create (B4A line: 99)


r2.SetOnTouchListener("Listview_Touch")
java.lang.ClassCastException: com.bcc.mobibcd.customlistview


   at anywheresoftware.b4a.agraham.reflection.Reflection.SetOnTouchListener(Reflection.java:1113)
   at com.bcc.mobibcd.claimdetails._activity_create(claimdetails.java:396)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
   at com.bcc.mobibcd.claimdetails.afterFirstLayout(claimdetails.java:89)
   at com.bcc.mobibcd.claimdetails.access$100(claimdetails.java:16)
   at com.bcc.mobibcd.claimdetails$WaitForLayout.run(claimdetails.java:74)
   at android.os.Handler.handleCallback(Handler.java:587)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:123)
   at android.app.ActivityThread.main(ActivityThread.java:4627)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.ClassCastException: com.bcc.mobibcd.customlistview


Any help with why this error is occurring would be much appreciated...

Thanks.
 

tunderin

Member
Licensed User
Longtime User
Thanks Erel,

I needed to add the listeners because the listviews totally cover up the underlying sliding panels & isolate them from touch - the panels don't slide when flicked.

Do you know of another way to pass touch gestures through the listviews to the panels beneath?

I'll try adding a listener to the CustomListView class itself & have it raise an event on flick...
 
Upvote 0

tunderin

Member
Licensed User
Longtime User
I considered (did not try) a transparent panel over the CustomListView but would the panel not consume a tap intended for the CustomListView?

EDIT:

May have answered my own question - In setting up an event handler for the transparent panels, it would seem to me that if I don't consume the touch action in my handler that it will pass through to the CustomListView.

Is that correct?
 
Last edited:
Upvote 0

tunderin

Member
Licensed User
Longtime User
Tried adding the transparent panels...

Erel,

After adding transparent panels, the panels (with views) slide now but the the listviews & CustomListViews do not operate, taps do not reach those views.

This is the event handler that I used:

B4X:
'handle touch event over listview
'change panels if it is a fling, otherwise let pass through to message que for listview to handle
Sub tPanels_Touch (Action As Int, X As Float, Y As Float)

   Select Action
      Case Activity.ACTION_DOWN
         startX = X
         startY = Y
      
      Case Activity.ACTION_UP
         If Abs(Y - startY) > 20%y Then Return
         If X - startX > 30%x Then            
            ChangePanel(False)
            Return True'consumed this event
            
         Else If startX - X > 30%x Then            
            ChangePanel(True)            
            Return True
            
         Else
            Return False'pass event to message que
            
         End If
         
   End Select
   
End Sub
 
Upvote 0

b4auser1

Well-Known Member
Licensed User
Longtime User
Erel,

Did I understand you correct, that It's necessary to use a code like this one ?
And in this case events will pass through to the enderlying ListView if return value is False ?
Dim r As Reflector
r.Target = tPanels
r.SetOnTouchListener("tPanels_Touch")



Sub tPanels_Touch (Action AsInt, X As Float, Y As Float)
Select ActionCase Activity.ACTION_DOWN
startX = X
startY = Y
Case Activity.ACTION_UP
If Abs(Y - startY) > 20%y Then Return
If X - startX > 30%x Then
ChangePanel(False)ReturnTrue'consumed this event
Else If startX - X > 30%x Then
ChangePanel(True) Return True
Else
Return False 'pass event to message que EndIf
End Select
End Sub
 
Upvote 0
Top