B4J Question Error Initializing B4XPlusMinus

AKJammer

Member
Licensed User
I'm trying to use the XUtils B4XPlusMinus but am having a problem with initialization. I can get it to work when it's created with the designer, but when I try to create it in a tableview I keep getting the error:
B4X:
Waiting for debugger to connect...
Program started.
Error occurred on line: 143 (B4XPlusMinus)
java.lang.RuntimeException: Object should first be initialized (B4XView).
   at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:32)
   at anywheresoftware.b4a.objects.B4XViewWrapper.getNodeObject(B4XViewWrapper.java:103)
   at anywheresoftware.b4a.objects.B4XViewWrapper.setText(B4XViewWrapper.java:292)
   at b4j.example.b4xplusminus._setindex(b4xplusminus.java:326)
   at b4j.example.b4xplusminus._setstringitems(b4xplusminus.java:101)
   at b4j.example.main._loadtableview3(main.java:330)

I think I'm doing the initialization just as I do the other objects I'm loading up, but I still get the error.

Can anyone point me in the right direction?

I've created a dummy project that shows what I'm doing.

Thanks,
Jim
 

Attachments

  • blah.zip
    3.7 KB · Views: 116

AKJammer

Member
Licensed User
Hmmm, Ok, so I create a B4XPlusMinus somewhere on the screen, make it invisible, then add one to the tableview like before? Sounds odd, but I'm willing to try. Is there any example of something like this? If I'm interpreting that wrong, would there be any way to add a custom view to a tableview as I'm doing with the other objects?

Thanks Erel!
 
Upvote 0

AKJammer

Member
Licensed User
I guess I haven't work with panes enough to see how that works. I created another layout "1", and created a pane, then added the custom view to the pane. Then in my main program I added tried adding the pane to the tableview. It no longer errors, but it doesn't show up in the tableview either.
B4X:
                   Case "spinner"
                       Dim pn1 As Pane
                       pn1.Initialize("spnEvent")
                       pn1.LoadLayout("1")
                      
                       pn1.Tag = intex
                       values(col) = pn1

Am I close?
 

Attachments

  • blah.zip
    4.9 KB · Views: 113
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You put spnRound inside an invisible pane so it doesn't appear.

The layout should only include the custom view.

You should also avoid loading layouts before setting the parent size. Better to write it like this:
B4X:
Dim pn1 As B4XView = xui.CreatePanel("") 'xui is a global XUI object.
pn1.SetLayoutAnimated(0, 0, 0, 140dip, 40dip)
pn1.LoadLayout("1")
spnRound.SetNumericRange(0, 100, 1)
 
Upvote 0

AKJammer

Member
Licensed User
Progress!! The pane wasn't invisible, but took it out so the custom view was the only thing in the layout and I was able to get it showing. But now that there is a Pane in the tableview, (showing the B4XPlusMinus), how do I extract the data out of it?

B4X:
Sub btnShow_Click
   If myTableView.SelectedRow >= 0 Then
       Dim row() As Object = myTableView.SelectedRowValues
       Dim name As TextField = row(0)
       Dim pnRnd As Pane = row(1)
       Dim spnRnd As B4XPlusMinus = pnRnd.GetNode(0)  'Doesn't work
       Dim ok As CheckBox = row(2)
       Dim id As Int = row(3)
       
       Log(name.Text)
       
       Log(spnRnd.SelectedValue)
       
       Log(ok.Checked)
       Log(id)
       
   End If
End Sub

I can pull out the Pane, but trying to find the underlying object is a bit beyond me. Node didn't work, and I couldn't find any other Pane methods that would apply. So how would I be able to get/set the custom view value within code using the Pane?
 
Upvote 0

AKJammer

Member
Licensed User
That was it. Thanks again Erel. I'm going to be using this in my first B4A app as well. Needed a way for people to make quick selections in minimum space. I'll probably have more questions as I move from B4J to B4A, but this environment has been wonderfully productive. Enjoy your Holidays!
Jim
 
Upvote 0
Top