Android Question CustomView.text is being changed to engineering notation

Bryan

Member
Licensed User
There are two problems I am having that are related to each other. It is related to this piece of code I'm using. I am only displaying the related parts of the code.

SelectedCat is a long numeric string 12345678901234567890
CustomView1.Text becomes 1.23457e+19
y becomes a -1

Then I get java.lang.ArrayIndexOutOfBoundsException: length=12; index=-1
because CustomView1.Text cannot be found in CatList as it should be. The string in Catlist is not the same because CustomView1.Text is in engineering notation. CatList should contain the string 12345678901234567890.

I don't want a long numeric string to be converted to engineering notation which is then causing the
ArrayIndexOutOfBoundsException. How do I fix this?
AutotextSizeLabel is a class module

B4X:
Sub Globals
Dim CatList As List
Dim CustomView1 As AutoTextSizeLabel

If kvs.ContainsKey("SelectedCat") Then
CustomView1.Text = (kvs.GetSimple("SelectedCat"))
y = CatList.IndexOf(CustomView1.Text)
CustomView1.Text = CatList.Get(y)
This is the AutoTextSizeLabel Class

B4X:
'Class module
Sub Class_Globals
    Private cvs As Canvas
    Private mLbl As Label
    Private su As StringUtils
    Private mTarget As Object, mEventName As String


End Sub

Public Sub Initialize (Target As Object, EventName As String)
mTarget = Target
mEventName = EventName
End Sub

Public Sub DesignerCreateView(Base As Panel, lbl As Label, props As Map)
    Dim bmp As Bitmap
    bmp.InitializeMutable(1dip,1dip)
    cvs.Initialize2(bmp)
    Base.AddView(lbl, 0, 0, Base.Width, Base.Height)
    Dim p As Panel
    p.Initialize("p")
    p.Color = Colors.Transparent
    Base.AddView(p, 0, 0, Base.Width, Base.Height)
    mLbl = lbl
    'Log("Text Size" & mLbl.TextSize)
    Dim r As Reflector
    r.Target = mLbl
    r.RunMethod4("setPadding", Array As Object(0,0,0,0), Array As String("java.lang.int", "java.lang.int", "java.lang.int", "java.lang.int"))
    r.RunMethod4("setIncludeFontPadding", Array As Object(False), Array As String("java.lang.boolean"))
    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 20 'was 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
Private Sub p_LongClick
   CallSub(mTarget, mEventName & "_LongClick")
End Sub

Private Sub p_Click
   CallSub(mTarget, mEventName & "_Click")
End Sub
Looks like
kvs.PutSimple("SelectedCat", CustomView1.Text) I have in code not listed above is the cause of the problem. If I view the contents of "SelectedCat" it is also in engineering notation. How do I stop this from doing this conversion. Any numeric value assigned to "SelectedCat" I want to be stored as a string.

Hope I am explaining this correctly.
Thank you
Bryan
 
Last edited:
Top