Android Question B4XPlusMinus ClassCastException

madru

Active Member
Licensed User
Longtime User
Morning,

how can I get the sending B4XPlusMinus (get his value) from a Pane (Panel) in a CustomListView?

B4X:
clv1.Add(addItemtoListview(PossibleFailure, clv1.AsView.Width, 40dip), "test")

Sub addItemtoListview(flist As List,  Width As Int, Height As Int) As Pane
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("CellItem")
 
    pmOne.SetNumericRange(0, 100, 1)
    pmTwo.SetNumericRange(0, 100, 1)
    pmThr.SetNumericRange(0, 100, 1)

    cbBox.Items.AddAll(flist)

    Return p
End Sub



B4X:
Sub pmOne_ValueChanged (Value As Object)
    Dim index As Int = clv1.GetItemFromView(Sender)
    Dim p As B4XView = clv1.GetPanel(index)

    Dim pmOne As B4XView = p.GetView(0)'0 as example'
    Dim pmTwo As B4XView = p.GetView(1)'1 as example'
    Dim pmThr As B4XView = p.GetView(2)'2 as example'
End Sub


this does work for textfields etc but not for this :(

B4X:
java.lang.ClassCastException: class b4j.example.b4xplusminus cannot be cast to class javafx.scene.Node (b4j.example.b4xplusminus is in unnamed module of loader 'app'; javafx.scene.Node is in module javafx.graphics of loader 'app')


THX
 
Last edited:

madru

Active Member
Licensed User
Longtime User
also an Error on B4A

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
.customlistview_getitemfromview (java line: 413)
java.lang.ClassCastException: b4a.example.b4xplusminus cannot be cast to android.view.View
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:88)
at anywheresoftware.b4a.objects.B4XViewWrapper.getParent(B4XViewWrapper.java:185)
at b4a.example3.customlistview._getitemfromview(customlistview.java:413)
at b4a.example.main._b4xplusminus1_valuechanged(main.java:393)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1082)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1037)
at b4a.example.b4xplusminus._setindex(b4xplusminus.java:371)
at b4a.example.b4xplusminus._increment(b4xplusminus.java:315)
at b4a.example.b4xplusminus._touch(b4xplusminus.java:561)
at b4a.example.b4xplusminus._pnlarrow_touch(b4xplusminus.java:341)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA$1.run(BA.java:352)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
this does work....

B4X:
Sub pmOne_ValueChanged (Value As Object)

'Log(Sender)
    Dim x As B4XPlusMinus=Sender
'   Dim x1 As B4XPlusMinus = x
    Log(x.SelectedValue)
End Sub

but i don't get the other components (to do some math) on the panel now
 
Last edited:
Upvote 0

madru

Active Member
Licensed User
Longtime User
this does work now, is this the correct approach ?



B4X:
    clv1.Add(addItemtoListview(PossibleFalure, clv1.AsView.Width, 40dip,c), "aa")
    c=c+1

Sub pmOne_ValueChanged (Value As Object)

        Dim x As B4XPlusMinus=Sender
        Dim p As B4XView = clv1.GetPanel(x.Tag)
        Dim x2,x3 As B4XPlusMinus
        x2 =p.GetView(1).Tag
        x3 =p.GetView(2).Tag

        Log(x2.SelectedValue)
        Log(x3.SelectedValue)

        x2.SelectedValue=10-x3.SelectedValue ' do something with the three values

End Sub

Sub addItemtoListview(flist As List,  Width As Int, Height As Int,count As Int) As Panel
         Dim p As B4XView = xui.CreatePanel("")
         p.SetLayoutAnimated(0, 0, 0, Width, Height)
         p.LoadLayout("CellItem")
         p.Tag=count
        
         pmOne.SetNumericRange(0, 100, 1)
         pmOne.Tag=p.Tag
         pmTwo.SetNumericRange(0, 100, 1)
         pmTwo.Tag=p.Tag
         pmThr.SetNumericRange(0, 100, 1)
         pmThr.Tag=p.Tag
   
         cbBox.Items.AddAll(flist)

         Return p
End Sub
 
Upvote 0
Top