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.
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?
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
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)
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?
Dim pnRnd As B4XView = row(1)
Dim spnRnd As B4XPlusMinus = pnRnd.GetView(0).Tag 'XUI Views store a reference to the class in the base panel tag property.
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