Android Question How load layout in a CustomView Class?

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
I would like to load a layout in a CustomView.

It is possible?

I'm trying this:
B4X:
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
    mBase = Base
    mBase.LoadLayout("mylayout")
End Sub

but I get this error:

java.lang.RuntimeException: java.lang.ClassCastException: java.lang.String can not be cast to android.widget.TextView


Thank you.
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Solution based on post @Erel

B4X:
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
    mBase = Base
   
    'The solution is to use CallSubDelayed.
    CallSubDelayed2(Me, "AfterLoadLayout", Props)
   
End Sub

Sub AfterLoadLayout(Props As Map)
    mBase.LoadLayout("mylayout")   
End Sub
 
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
But I don't get that error. Try to recreate myLayout

P.S. I don't get that error... only because I ran the project in debug mode

Thank you.

Solution based on @Erel

B4X:
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
    mBase = Base
   
    ' The solution is to use CallSubDelayed.
    CallSubDelayed2(Me, "AfterLoadLayout", Props)
   
End Sub

Sub AfterLoadLayout(Props As Map)
    mBase.LoadLayout("mylayout")   
End Sub
 
Upvote 0
Top