Android Question Problems with custom view

FrankBerra

Active Member
Licensed User
Longtime User
Hi all!
I am trying learn how Custom View works.

I have created a little example: it works in debug mode but it crashes in release mode. What is wrong?

I attach here the example project

Thanks in advance!
 

Attachments

  • TestCustomView.zip
    10 KB · Views: 146

FrankBerra

Active Member
Licensed User
Longtime User
The solution suggested by Klaus is working as expected...anyway i am wondering how to deal with more complex designs. As written in XUI instructions (https://www.b4x.com/android/forum/threads/b4x-xui-cross-platform-native-ui-library.84359/) it suggest to "Use the designer to build the interface. The designer hides many of the differences between the platforms.". How can i load the designs made with designer without throwing exceptions?

Anyway the error thrown by the example in the first post is:
B4X:
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
boton_designercreateview (java line: 80)
java.lang.RuntimeException: java.lang.ClassCastException: java.lang.String 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 b4a.example.boton._designercreateview(boton.java:80)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:67)
    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:334)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at b4a.example.main.afterFirstLayout(main.java:102)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6809)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.ClassCastException: java.lang.String 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)
    ... 20 more
--------- beginning of crash
 
Last edited:
Upvote 0

FrankBerra

Active Member
Licensed User
Longtime User
If i use "sleep", what about performance in loading dozens of items with the same layout? In this case should i create the template of the layout by code instead with the designer?
 
Upvote 0
Top