I am trying to create AutoTextSizeLabel manually on the code. This code does not have layout.
I am using an expanded version I made of AutoTextSizeLabel to resemble more a Label and be more easily changed on the source code.
However I cannot find a way to make it work when I create manually.
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
I am trying this code:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
I am trying to use this ways, but it crashes:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
I have created that initialize2 because setText needs some stuff initialized.
However the CSV.Initialize causes this crash:
		
		
	
	
		 
	
What can I do to create manually ?
			
			I am using an expanded version I made of AutoTextSizeLabel to resemble more a Label and be more easily changed on the source code.
However I cannot find a way to make it work when I create manually.
			
				B4X:
			
		
		
		Sub Class_Globals
    Private cvs As Canvas
    Private mLbl As Label
    Private su As StringUtils
    Private EventName As String 'ignore
    Private CallBack As Object 'ignore
End Sub
Public Sub Initialize (vCallback As Object, vEventName As String)
    EventName = vEventName
    CallBack = vCallback
End Sub
public Sub Initialize2(lbl As Label, vEventName As String)
    EventName = vEventName
    CallBack = Null
    mLbl = lbl
    Dim bmp As Bitmap
    bmp.InitializeMutable(1,1) 'ignore
    cvs.Initialize2(bmp)
End Sub
Public Sub DesignerCreateView(Base As Panel, lbl As Label, props As Map)
    Dim bmp As Bitmap
    bmp.InitializeMutable(1,1) 'ignore
    cvs.Initialize2(bmp)
    Dim parent As Panel = Base.Parent
    
    parent.AddView(lbl, Base.Left, Base.Top, Base.Width, Base.Height)
    Base.RemoveView
    mLbl = lbl
    mLbl.Padding = Array As Int(0, 0, 0, 0)
    Dim jo As JavaObject = mLbl
    jo.RunMethod("setIncludeFontPadding", Array(False))
    setText(mLbl.Text)
End Sub
Public Sub setText(value As String)
    mLbl.Text = value
    Dim multipleLines As Boolean = mLbl.Text.Contains(CRLF)
    Dim size As Float
    For size = 2 To 80
        If CheckSize(size, multipleLines) Then Exit
    Next
    size = size - 0.5
    If CheckSize(size, multipleLines) Then size = size - 0.5
    mLbl.TextSize = size
End Sub
'returns true if the size is too large
Private Sub CheckSize(size As Float, MultipleLines As Boolean) As Boolean
    mLbl.TextSize = size
    If MultipleLines Then
        Return su.MeasureMultilineTextHeight(mLbl, mLbl.Text) > mLbl.Height
    Else
        Return cvs.MeasureStringWidth(mLbl.Text, mLbl.Typeface, size) > mLbl.Width Or _
            su.MeasureMultilineTextHeight(mLbl, mLbl.Text) > mLbl.Height
    End If
End Sub
Public Sub getText As String
    Return mLbl.Text
End Sub
Public Sub setVisible(Value As Boolean)
    mLbl.Visible = Value
End Sub
public Sub getVisible As Boolean
    Return mLbl.Visible
End Sub
public Sub setTextSize(Value As Int)
    mLbl.TextSize = Value
End Sub
public Sub getTextSize As Int
    Return mLbl.TextSize
End Sub
public Sub RequestFocus
    mLbl.RequestFocus
End Sub
Private Sub mLbl_Click
    Dim e As String = EventName&"_Click"
    If SubExists(CallBack, e) Then
        CallSub(CallBack, e)
    End If
End Sub
Public Sub getGravity As Int
    Return mLbl.Gravity
End Sub
Public Sub setGravity(value As Int)
    mLbl.Gravity = value
End Sub
Public Sub setTypeface(value As Typeface)
    mLbl.Typeface = value
End Sub
public Sub getTypeface As Typeface
    Return mLbl.Typeface
End Sub
public Sub getTextColor As Int
    Return mLbl.TextColor
End Sub
Public Sub setTextColor(value As Int)
    mLbl.TextColor = value
End Sub
public Sub View As Label
    Return mLbl
End Sub
public Sub setEnabled(Value As Boolean)
    mLbl.Enabled = Value
End Sub
public Sub getEnabler As Boolean
    Return mLbl.Enabled
End Sub
public Sub setHeight(Value As Int)
    mLbl.Height = Value
End Sub
public Sub getHeight As Int
    Return mLbl.Height
End Sub
public Sub BringToFront
    mLbl.BringToFront
End SubI am trying this code:
			
				B4X:
			
		
		
		                Dim lbl As Label
                lbl.Initialize("")
                Parent.AddView(lbl, bt(i, j).Left+2dip, bt(i, j).Top+10dip, FDefaultWidth-2dip, 30dip)
                
                Dim L As AutoTextSizeLabel
                L.Initialize2(lbl, "")I am trying to use this ways, but it crashes:
			
				B4X:
			
		
		
		                Dim lbl As Label
                lbl.Initialize("")
                Parent.AddView(lbl, bt(i, j).Left+2dip, bt(i, j).Top+10dip, FDefaultWidth-2dip, 30dip)
                
                Dim L As AutoTextSizeLabel
                L.Initialize2(lbl, "")
L.Text = "example"I have created that initialize2 because setText needs some stuff initialized.
However the CSV.Initialize causes this crash:
What can I do to create manually ?
 
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		