Android Question Label with hanging indents?

jo1234

Active Member
Licensed User
Longtime User
Hi,

I would like to show stepwise instructions with hanging indents in a multiline label.
Something like:
1.) First do text text text,
text text text​
2.) Then text text text text
text text text
indent.png


The text is translated and differs in length between the different languages.

Is there a way to use SpannableString and android.text.style.LeadingMarginSpan in a label to get this done?

Thanks,
Johannes
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("444")
   Sleep(0)
   Dim cs As CSBuilder
   cs.Initialize
   CallSub3(Me, "AddLeadingMarginSpan", cs, Array As Int(0dip, 30dip))
   cs.Append("1) First do text text text, text text text text text text text").PopAll
   CallSub3(Me, "AddLeadingMarginSpan", cs, Array As Int(0dip, 30dip))
   cs.Append(CRLF).Append("2) Second do text text text, text text text text text text text").PopAll
   Label1.Text = cs
End Sub

Sub AddLeadingMarginSpan(cs As Object, FirstAndRest() As Int)
   Dim span As JavaObject
   span.InitializeNewInstance("android.text.style.LeadingMarginSpan.Standard", Array(FirstAndRest(0), FirstAndRest(1)))
   Dim jo As JavaObject = cs
   jo.RunMethod("open", Array(span))
End Sub

SS-2018-03-09_08.33.33.png


You must use CallSub to call AddLeadingMarginSpan due to the way CSBuilder is implemented. The Sleep(0) is required if you want to call it from Activity_Create as otherwise the CallSub will be ignored (the activity is considered paused at that point).
 
Upvote 0
Top