Android Question Panel.LoadLayout Error

Guenter Becker

Active Member
Licensed User
Whish you a happy christmas,

I am developing a customcontrol. I like to use a panel and load a layout build with the designer into it and than add the panel to the base of the custom control:

Code in creation sub Test 1:
    mprops = Props
    Panel.Width = mBase.Width:Panel.Height=mBase.height
    Panel.LoadLayout("ActionBarPanel")
    mBase.AddView(Panel,0,0,mBase.Width,mBase.Height)

Code in creation sub Test 2:
    mprops = Props
    Panel.Width = mBase.Width:Panel.Height=mBase.height
    mBase.AddView(Panel,0,0,mBase.Width,mBase.Height)
    Panel.LoadLayout("ActionBarPanel")

The layout only contains a panel with some child views a label and an imageview.

If I use the customcontrol on a layout loaded into an activity and run the app I get the error as follows:

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 68 (extActionBar)
java.lang.RuntimeException: java.lang.ClassCastException: b4a.example.extactionbar cannot be cast to android.widget.TextView
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
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.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:61)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
at b4a.example.main._activity_create(main.java:396)
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 b4a.example.main.afterFirstLayout(main.java:105)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassCastException: b4a.example.extactionbar cannot be cast to android.widget.TextView
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:44)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
... 28 more

Please can anyone help me whats going wrong?
 

Guenter Becker

Active Member
Licensed User

Thank you, following the information I solved it:

Solved:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Test") 'Load Layout with custom control and jump to Activity_Resume
    CallSubDelayed(Me, "Initialization2")
    'Wait that custom controll is full initialized and jump to initialize2'
End Sub

Sub Activity_Resume
' jump back to Activit_Create and CallSubDelayed
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

#region --- Initialization ---
Sub Initialization2
    ' now ist able to work tith the custom control
    extActionBar1.MainTitle.text = "Test"
End Sub
 
Upvote 0
Top