Android Question B4XCOMBO on CustomListView - Finding clv item

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I have a B4xCombobox on a panel in a custom list view which has multiple instances of the panel.

When the user changes a combobox the _SelectedIndexChanged event is called.

Normally I would use:
B4X:
    Private vw As B4XView = Sender

    Private indx As Int  = clv.GetItemFromView(vw) ' Crash on this line
    Log("Clv Index = "& indx)
End Sub

But this causes a crash. Is there any way to find out which item in a CLV is pressed ?

Thanks

Error occurred on line: 875 (LandingPage)
java.lang.ClassCastException: uk.co.digitwell.tickedit.b4xcombobox cannot be cast to android.view.View
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:69)
at anywheresoftware.b4a.objects.B4XViewWrapper.getParent(B4XViewWrapper.java:166)
at b4a.example3.customlistview._getitemfromview(customlistview.java:408)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1068)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1023)
at uk.co.digitwell.tickedit.b4xcombobox._raiseevent(b4xcombobox.java:159)
at uk.co.digitwell.tickedit.b4xcombobox._cmbbox_itemclick(b4xcombobox.java:145)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA$1.run(BA.java:335)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:180)
at android.app.ActivityThread.main(ActivityThread.java:6944)
 

walterf25

Expert
Licensed User
Longtime User
I have a B4xCombobox on a panel in a custom list view which has multiple instances of the panel.

When the user changes a combobox the _SelectedIndexChanged event is called.

Normally I would use:
B4X:
    Private vw As B4XView = Sender

    Private indx As Int  = clv.GetItemFromView(vw) ' Crash on this line
    Log("Clv Index = "& indx)
End Sub

But this causes a crash. Is there any way to find out which item in a CLV is pressed ?

Thanks

Error occurred on line: 875 (LandingPage)
java.lang.ClassCastException: uk.co.digitwell.tickedit.b4xcombobox cannot be cast to android.view.View
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:69)
at anywheresoftware.b4a.objects.B4XViewWrapper.getParent(B4XViewWrapper.java:166)
at b4a.example3.customlistview._getitemfromview(customlistview.java:408)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1068)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1023)
at uk.co.digitwell.tickedit.b4xcombobox._raiseevent(b4xcombobox.java:159)
at uk.co.digitwell.tickedit.b4xcombobox._cmbbox_itemclick(b4xcombobox.java:145)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA$1.run(BA.java:335)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:180)
at android.app.ActivityThread.main(ActivityThread.java:6944)
B4X:
Private vw As View = Sender
Try changing
B4X:
Private vw As B4XView = Sender
To
B4X:
Private vw As View = Sender

Regards,
Walter
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Walter,

I'm not sure that will make any difference as GetItemFromView takes a B4XView.
the error becomes :
java.lang.ClassCastException: uk.co.digitwell.tickedit.b4xcombobox cannot be cast to android.view.View
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Walter,

I'm not sure that will make any difference as GetItemFromView takes a B4XView.
the error becomes :
java.lang.ClassCastException: uk.co.digitwell.tickedit.b4xcombobox cannot be cast to android.view.View
How about if you change it to this
B4X:
Dim index As Int = CLV.GetItemFromView(Sender)

That should also work.
Walter
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Sorry.
same error as above.
java.lang.ClassCastException: uk.co.digitwell.tickedit.b4xcombobox cannot be cast to android.view.View

I think I have a workaround.
I made the mBase item of the B4xCombo public.

so the code is now:
B4X:
    Private b4xcb As B4XComboBox = Sender

    Private vw As B4XView= b4xcb.mBase
    
    Private indx As Int  = clv.GetItemFromView(vw)
    Log("Clv Index = "& indx)

This now works but is not ideal as I don't like to alter provided controls.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Sorry.
same error as above.
java.lang.ClassCastException: uk.co.digitwell.tickedit.b4xcombobox cannot be cast to android.view.View

I think I have a workaround.
I made the mBase item of the B4xCombo public.

so the code is now:
B4X:
    Private b4xcb As B4XComboBox = Sender

    Private vw As B4XView= b4xcb.mBase
   
    Private indx As Int  = clv.GetItemFromView(vw)
    Log("Clv Index = "& indx)

This now works but is not ideal as I don't like to alter provided controls.
Interesting, how about if you change the code to this
B4X:
Dim vw as Spinner = Sender
Dim index As Int = CLV1.GetItemFromView(vw)

Essentially if you are using B4A the control is a spinner, so this should work.

Walter
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Sorry walter, same error as before.

java.lang.ClassCastException: uk.co.digitwell.tickedit.b4xcombobox cannot be cast to android.view.View

I think the problem is that the Sender is the B4xCombo class which is not inherited from View.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Sorry walter, same error as before.

java.lang.ClassCastException: uk.co.digitwell.tickedit.b4xcombobox cannot be cast to android.view.View

I think the problem is that the Sender is the B4xCombo class which is not inherited from View.
You can try adding the following sub to the B4XComboBox class
B4X:
Public Sub AsView As B4XView
    #if B4J
    return cmbBox
    #Else If B4i
    return mBtn
    #Else
    return cmbBox
    #End If
End Sub

And then to find out the view's index
B4X:
Dim vw as B4XView = Sender
Dim index As Int = CLV1.GetItemFromView(vw.AsView)

Walter
 
Upvote 0
Top