Android Question Setting a String variable to a CS style

Mark Stuart

Active Member
Licensed User
Longtime User
I have a String code statement that I want to set with a CSBuilder statement.
It goes like this:
B4X:
    Dim cs As CSBuilder
    cs.Initialize
    cs.Append("Phone Types ")
    cs.Typeface(Typeface.STYLE_ITALIC)                    '<==== Types do not match
    cs.Append("(").Append($"${phonetype}"$).Append(")")
    cs.Typeface(Typeface.DEFAULT)
    cs.PopAll
    
    Dim ptTitle As String = cs
The string then gets used in the code to load a ListView.AddTwoLinesAndBitmap2(ptTitle,.....)
But I get this syntax error: Types do not match on the line shown above.
How come it gives the syntax error on that line and not the other line: cs.Typeface(Typeface.DEFAULT)?

The appearance should look like this in the ListView:
Phone Types (Home)
 

Mark Stuart

Active Member
Licensed User
Longtime User
So this is what I changed but it too didn't work as expected:

B4X:
    Dim lbl As Label
    lbl.Initialize("")
    Dim cs As CSBuilder
    cs.Initialize
    cs.Append("Phone Types ")
    cs.Typeface(Typeface.CreateNew(Typeface.DEFAULT,Typeface.STYLE_ITALIC))
    cs.Append("(").Append($"${phonetype}"$).Append(")")
    cs.Typeface(Typeface.DEFAULT)
    cs.PopAll
    'Dim ptTitle As String = cs
    lbl.Text = cs

    lvSettings.AddTwoLinesAndBitmap2(lbl.Text,....
 
Upvote 0

Mark Stuart

Active Member
Licensed User
Longtime User
I am doing it in a normal label field. Not sure you can do this in a ListView.AddTwoLines
It seems that way. It's not a deal breaker, but would have been nice.
After all, the ListView.AddTwoLinesAndBitmap2(Text1 as CharSequence,...), is a CharSequence, which the CS result is.
I would call it a bug then.
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I don't think you can use ListView for what you want to do.

But maybe ListView.TwoLinesLayout will give you the layout for two lines and maybe you can modify it to do what you want. But I don't really think so in this case
 
Upvote 0
Top