Android Question Problem: Rare behavior of RichString, cursor loose when use backcolor.

ELCHARO

Member
Licensed User
Longtime User
Guys, when run this code in Phone and Emulator. Android 4+ the cursor disappear when use backcolor. If a general problem or make some mistake.
Thanks again.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    str.Initialize(str)
    Activity.AddView(str,0,0,200,200)
End Sub

Sub Activity_Resume
    str.Text="Texto========11111111111111Texto"
    a=MakeColor(str.Text)
    str.Text=a
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub MakeColor(sourcetxt As String) As RichString
    Dim backcolor,frontcolor,numcolor,colorlevel As Int                'Take current color string
    Dim wordpos As Long
    Dim inpstr As String               
    inpstr=sourcetxt
  
    richstr.Initialize(inpstr)
'==============================================================  
    backcolor=Colors.black     ' PROBLEM, WHEN USE BACKCOLOR
'==============================================================
    numcolor=Colors.white
    frontcolor=Colors.White
    colorlevel=Colors.white
  
    For wordpos=0 To inpstr.Length-1   ' navigate de string.
        Select inpstr.CharAt(wordpos)   ' analize this char. 
            Case "+","=","/","*",".",":"," ","-","#","%","<",">","&"
                    onelinecolor(Colors.Blue,backcolor, wordpos, wordpos+1)
            Case Chr(10),Chr(32),Chr(9),Chr(13),Chr(15),Chr(44),Chr(34) ,Chr(39) 'SPACE TAB,LF,CR,COMA
                    richstr.backcolor(backcolor, wordpos, wordpos+2)  
            Case "1","2","3","4","5","6","7","8","9","0" 
                    onelinecolor(numcolor,backcolor, wordpos, wordpos+1)
            Case Else
                    richstr.Color(Colors.White,wordpos,wordpos+1 )   'CURSOR WORK HERE BECAUSE DON'T USE BACKCOLOR

        End Select
    Next
    Return richstr  

End Sub

Sub onelinecolor (col As Int,bcol As Int,pos As Int,size As Int)
    richstr.Color(col,pos,size )   ' color funciones
    richstr.backColor(bcol,pos,size )   ' color funciones
End Sub



ANY SUGESTIONS, WHY?

Thanks Ricardo.
 

DonManfred

Expert
Licensed User
Longtime User
ANY SUGESTIONS, WHY?
maybe because there is a method with the same name.
B4X:
richstr.backcolor(backcolor, wordpos, wordpos+2)
Try to give the local variable(s) another name. for ex.
B4X:
Dim bgcolor
[..]
richstr.backcolor(bgcolor, wordpos, wordpos+2)
 
Upvote 0

ELCHARO

Member
Licensed User
Longtime User
Correct answer, thanks DonManfred.

The problem is resolve.
I need to check how i write the declarations ,because i believe B4X resolve this things. But not.
 
Last edited:
Upvote 0
Top