Android Question Pages and Background Colors and Choices

brianwiz12

Active Member
Licensed User
Longtime User
Hello,

I have been enthralled with pages. I love the idea of transporting one name, text box answer through my whole app on multiple pages.

Now im kinda stuck in between coding without pages and coding with pages.

Is their a way to have users choose the color like before pages with--- XUI VIEWS Example

I have tried to minic the code and take the

B4X:
Sub btnColor_Click
    
    Wait For (Dialog.ShowTemplate(ColorTemplate, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Base.Color = ColorTemplate.SelectedColor
    End If
End Sub

and use it in pages. I get an error clicking the button

B4X:
Error occurred on line: 95 (B4XDialog)
java.lang.RuntimeException: Object should first be initialized (B4XView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getViewObject(B4XViewWrapper.java:101)
    at anywheresoftware.b4a.objects.B4XViewWrapper.asPanelWrapper(B4XViewWrapper.java:104)
    at anywheresoftware.b4a.objects.B4XViewWrapper.GetAllViewsRecursive(B4XViewWrapper.java:304)
    at b4a.example.b4xdialog$ResumableSub_ShowCustom.resume(b4xdialog.java:1009)
    at b4a.example.b4xdialog._showcustom(b4xdialog.java:944)
    at b4a.example.b4xdialog$ResumableSub_ShowTemplate.resume(b4xdialog.java:168)
    at b4a.example.b4xdialog._showtemplate(b4xdialog.java:125)
    at b4a.example.b4xmainpage$ResumableSub_btnColor_Click.resume(b4xmainpage.java:153)
    at b4a.example.b4xmainpage._btncolor_click(b4xmainpage.java:127)
    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$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

Im not an expert or even more then a dabber in this. But i really like pages its actually a little easier for me to understand.

With that being said im not converting all my programs over but when i build new ones i want to try my best to use it.
 

brianwiz12

Active Member
Licensed User
Longtime User
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Public txtUser As B4XFloatTextField
    Public txtGameOne As B4XFloatTextField
    Public btncolor As SwiftButton
    Private btnLogin As B4XView
    Public Page2 As B4XPage2
    Public Page3 As B4XPage3
    Private Base As B4XView
    Private Dialog As B4XDialog
    Private xui As XUI
    Private ColorTemplate As B4XColorTemplate
  

End Sub

'You can add more parameters here.
Public Sub Initialize
  
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("welcome")
    Page2.Initialize
    B4XPages.AddPage("Page 2", Page2)
    Page3.Initialize
    B4XPages.AddPage("Page 3", Page3)

    Dialog.Initialize (Base)
    Base = Root1
    ColorTemplate.Initialize
  

End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Sub btnColor_Click
    Wait For (Dialog.ShowTemplate(ColorTemplate, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Base.Color = ColorTemplate.SelectedColor
    End If
End Sub

Sub btnLogin_Click
    B4XPages.ShowPageAndRemovePreviousPages("Page 2")
End Sub

Sub txtUser_TextChanged (Old As String, New As String)
    btnLogin.Enabled = New.Length > 0
  
End Sub

Sub txtUser_EnterPressed
    If btnLogin.Enabled Then btnLogin_Click
End Sub

Sub B4XPage_Appear
    txtUser.Text = ""
    txtGameOne.Text = ""
End Sub

Here is the code. In the original view email it had base = activity. Since this was not under activity create i changed it to base = root1 which i believe would be similar.

I still get the same error above after double checking and updating to ensure i was initializing.

Update i even tried to use the public initialize sub within the pages for the colortemplate and dialog
 
Last edited:
Upvote 0

brianwiz12

Active Member
Licensed User
Longtime User
Here is the attached. This is where i play around with code before implementing into a program
 

Attachments

  • B4AProject.zip
    19.9 KB · Views: 125
Upvote 0

agraham

Expert
Licensed User
Longtime User
1) You are still using Base in btnColor_Click, change it to Root.Color

2) You haven't initialised Dialog. It works (as far as it goes) with this
B4X:
'You can add more parameters here.
Public Sub Initialize
   
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Dialog.Initialize (Root)
    ColorTemplate.Initialize
   
    'load the layout to Root
    Root.LoadLayout("welcome")
    Page2.Initialize
    B4XPages.AddPage("Page 2", Page2)
    Page3.Initialize
    B4XPages.AddPage("Page 3", Page3)
End Sub
You need to pay attention to any purple squiggly underlines and look at the error list above the Logs pane.
 
Upvote 0

brianwiz12

Active Member
Licensed User
Longtime User
Thank you for the assist very interesting. I thought i tried that without the base i must never had put the code in B4XPage_Created. Thank you for teaching me and explaining
 
Upvote 0
Top