Android Question Doubt on CharSequence / CSBuilder usage

Discussion in 'Android Questions' started by FERNANDO SILVEIRA, Jun 5, 2018.

  1. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    Hello guys,

    I read this topic and was trying to implement some text enhancements to my app. It happens that the CS elements seems to work directly on the view and, in my case, I work literals and fields in string literals and, at the end, combine these string literals on the final label.text view object. Then I noticed that this approach (use of intermediate literals) produce no effect on the result, resulting no formatting at all at the end, as can be seen in the attached image,

    It worked, however, when I prepare the CS string and send it right to the label.text view.

    Is there other way to apply formatting to my resulting text? HTML tags <B> </B> <I> </I> would be enough.

    Regards,
    Fernando

    Code:
    Select wCodEvento
                
    Case     1    '  *** USING CS ON THE 1ST CASE JUST FOR TEST ***
                   
                    cs.Initialize.Append(IIF(wRegistro(
    7) = Null"Nascid" & wSufixo, "Nascid" & wSufixo & " em " & wRegistro(7)) & " no dia ")
                    cs.Bold.Color(
    Colors.Green).Append(wDataEvento).Pop.Pop 'two pops: the first removes the green color and the second removes the bold style
                    cs.Append(". ").PopAll
                    wTxtNascimento = cs
    '                lblDetalhePessoa.text = cs
    '                Return

                
    Case     2    
                    wTxtCasamento = wTxtCasamento & "Casad" & wSufixo & " no dia " & wDataEvento & " com " & wRegistro(8) & IIF(wRegistro(7) = Null""", em " & wRegistro(7)) & ". "
                
    Case     3    
                    wTxtBatizado = "Batizad" & wSufixo & " no dia " & wDataEvento & IIF(wRegistro(7) = Null""", em " & wRegistro(7)) & ". "
            
    End Select
        
    Next
     


    ' *** CS text (wTxtNascimento) prepared above does nothing when combined as below
        lblDetalhePessoa.text = wTxtApelido & wTxtIdade & wTxtNascimento & wTxtPaiMae & wTxtCasamento & wTxtFalecimento & wTxtCrismado & wTxt1Comunhao & wTxtFormado & wTxtDivorcio & wTxtEmancipado
    upload_2018-6-5_13-47-3.png
     
  2. Mahares

    Mahares Well Known Member Licensed User

    Fernando: I think you have to do something like this for it to work. This will work:
    Code:
    Dim cs As CSBuilder
        
    Dim strvar1 As String ="BRAZIL IS IN WORLD CUP 2018."
        
    Dim strvar2 As String =" FERNANDO IS LOOKING FORWARD"
        
    Dim strvar3 As String =" TO A WIN."  
        cs.initialize.Color(
    Colors.Red).Append(strvar1).Color(Colors.Blue).Append(strvar2) _
        .Color(
    Colors.Green).Append(strvar3).PopAll
        lbl.Text=cs
     
  3. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    Hello, Mahares
    You right, it works doin this way when the output is a label.text. However I have to prepare my text string in advance and only when everything is ready concatenate these strings to label.text.
     
  4. Mahares

    Mahares Well Known Member Licensed User

    When everything is ready and all variables are defined, that is when you create your csbuilder and stick it in the label text. That is what my example does, unless I am not understanding fully the issue
     
    FERNANDO SILVEIRA likes this.
  5. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    Look at this code:
    Code:
    Dim cs As CSBuilder
        
    Dim strvar1 As String ="BRAZIL IS IN WORLD CUP 2018."
        
    Dim strvar2 As String =" FERNANDO IS LOOKING FORWARD"
        
    Dim strvar3 As String =" TO A WIN."
        cs.initialize.Color(
    Colors.Red).Append(strvar1).Color(Colors.Blue).Append(strvar2) _
        .Color(
    Colors.Green).Append(strvar3).PopAll
        Label1.Text=cs                    
    ' <=== WORKS FINE
      
        
    Dim strvar4 As String
        
    Dim strvar5 As String

        strvar4 = cs.initialize.Color(
    Colors.Red).Append(strvar1).Color(Colors.Blue).Append(strvar2) _
        .Color(
    Colors.Green).Append(strvar3).PopAll

        strvar5 = cs.initialize.Color(
    Colors.Red).Append(" Mahares is").Color(Colors.Blue).Append(" a nice ") _
        .Color(
    Colors.Green).Append("guy").PopAll
      
        Label2.Text = strvar4 & strvar5    
    ' <=== DOES NOTHING - And I can only set label2.text at the end, otherwise the code would become a monster
    In my case, a single label2.text is the result of concatenation of up to 10 strvars...
     
  6. Mahares

    Mahares Well Known Member Licensed User

    You can create multiple csbuilders (one for each variable string) and concatenate them into the label text . See example below:
    Code:
    Dim cs As CSBuilder
        
    Dim strvar As String ="BRAZIL CAN WIN THE WORLD CUP IN 2018"
        cs.initialize.Color(
    Colors.Red).Append(strvar.SubString2(05)).Color(Colors.Blue).Append(strvar.SubString2(58)) _
        .Color(
    Colors.Green).Append(strvar.SubString(8)).PopAll
        
    Dim cs1 As CSBuilder
        
    Dim strvar As String ="  FERNANDO"
        cs1.initialize.Color(
    Colors.Magenta).Append(strvar).PopAll
        
    Dim cs3 As CSBuilder
        cs3.Initialize.Append(cs).Append(cs1)
        lbl.Text=cs3
     
    FERNANDO SILVEIRA and DonManfred like this.
  7. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    Uhmmmmm... Now you are talking *lol*
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice