Android Question Custom control with CustomListview

Roberto P.

Well-Known Member
Licensed User
Longtime User
I want to create a custom control that uses a CustomListView.
I created a resource, loaded the layout but by mistake.

How can I do it?

B4X:
#DesignerProperty: Key: BooleanExample, DisplayName: Show Seconds, FieldType: Boolean, DefaultValue: True
#DesignerProperty: Key: TextColor, DisplayName: Text Color, FieldType: Color, DefaultValue: 0xFFFFFFFF, Description: Text color

Sub Class_Globals
    Private mEventName As String 'ignore
    Private mCallBack As Object 'ignore
    Private mBase As B4XView 'ignore
    Private xui As XUI 'ignore
    Private mCLVMaster As CustomListView
End Sub

Public Sub Initialize (Callback As Object, EventName As String)
    mEventName = EventName
    mCallBack = Callback
End Sub

'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
    mBase = Base
      Dim clr As Int = xui.PaintOrColorToColor(Props.Get("TextColor")) 'Example of getting a color value from Props
        
        
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 100%x, 100%y)
    p.LoadLayout("frmCLV")

End Sub

Private Sub Base_Resize (Width As Double, Height As Double)
 
End Sub

** Activity (frmcatalogclv) Create, isFirst = true **
ccatalog_designercreateview (B4A line: 25)
p.LoadLayout("frmCLV")
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 anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(B4XViewWrapper.java:292)
at b4a.example.ccatalog._designercreateview(ccatalog.java:97)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
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.frmcatalogclv._activity_create(frmcatalogclv.java:355)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at b4a.example.frmcatalogclv.afterFirstLayout(frmcatalogclv.java:104)
at b4a.example.frmcatalogclv.access$000(frmcatalogclv.java:17)
at b4a.example.frmcatalogclv$WaitForLayout.run(frmcatalogclv.java:82)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
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)
... 21 more
java.lang.RuntimeException: java.lang.ClassCastException: java.lang.String cannot be cast to android.widget.TextView
** Service (starter) Destroy (ignored)**
** Activity (main) Resume **
 

klaus

Expert
Licensed User
Longtime User
What exactly are you trying to do?
CustomListView is now an internal library xCustomLibrary, why do you want to change the internal code in Public Sub DesignerCreateView ?
THere are many threads about xCustomListView .

1579716510113.png
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
What exactly are you trying to do?
CustomListView is now an internal library xCustomLibrary, why do you want to change the internal code in Public Sub DesignerCreateView ?
THere are many threads about xCustomListView .

View attachment 87713

Hi Klaus
I need to do a custom control that contains a CustomListView to be able to manage it inside.

Unfortunately, you can no longer include a custom list view via code and I tried to do it by creating a resource.

I hope it is clear
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I need to do a custom control that contains a CustomListView to be able to manage it inside.
I have never really used xCustomListView and never in a another CustomView.
Anyway, the best way to learn how it works is to look at the tutorials.
From what I remember, you can add a xCustomListView in the Designer, just one xCustomListView object.
Then, you can add the different componants as usual.
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
You need to add Sleep(0) before you load the layout. This is required because currently it is not possible to load a layout while the parent layout is loaded.


thank Erel

I tried it but doesn't work. The CustomListView is not inizialized.

B4X:
'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
    mBase = Base
  Dim clr As Int = xui.PaintOrColorToColor(Props.Get("TextColor")) 'Example of getting a color value from Props
        
        
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,100%x, 100%y)
    
    Sleep(0)
    mBase.AddView(p, 0,0,100%x,100%y)
    Sleep(0)
    p.LoadLayout("frmCLV")
    
    
    Log( "inizialized " & mCLVMaster.IsInitialized)

    For i = 0 To 10
    
        mCLVMaster.AddTextItem("Item " & i, i)
    Next
    

End Sub
 
Upvote 0
Top