Android Question How load layout in a CustomView Class?

Eme Fibonacci

Well-Known Member
Licensed 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
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
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

LucaMs

Expert
Licensed User
Explanation of why my previous posts (just to not seem too stupid :p).

After reading your question, I immediately thought to CallSubDelayed, because I assumed that it is necessary that the DesignerCreateView is complete before loading the layout; but, since I want always be sure, I wanted to try anyway directly.
 
Upvote 0
Top