Android Code Snippet Change Tab Stop on Labels and Listview using CSBuilder

b4a_screenshot.png As the title says. The method is based on span manipulation used in the thread below. If this is an existing solution, let me know, I couldn't find it.

https://www.b4x.com/android/forum/posts/571640/

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Color = Colors.LightGray
    lbl.TextSize = 30
    Activity.addView(lbl, 10dip, 50dip, Activity.Width-20dip, 50dip)
    Dim cs As CSBuilder
    cs.Initialize
    cs.color(Colors.Blue).Append("here" & TAB & "there")
    Sleep(0)        'without this it doesn't work
    CallSub3(Me, "AddFirstTabStop", cs, Array As Int(350dip))
    lbl.Text = cs.PopAll
End Sub

Sub AddFirstTabStop(cs As Object, atStop() As Int)
    Dim span As JavaObject
    span.InitializeNewInstance("android.text.style.TabStopSpan.Standard", Array(atStop(0)))
    Dim jo As JavaObject = cs
    jo.RunMethod("open", Array(span))
End Sub

Note: I have tested it with Listview and it works, however if you change the backgroundColor of the item, the tab space color is not changed.

b4a_screenshot.png
 

Attachments

  • columnized_listview.png
    columnized_listview.png
    10.4 KB · Views: 339
Last edited:
Top