Android Question Label with hanging indents?

jo1234

Member
Licensed 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

Administrator
Staff member
Licensed 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


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).
 
Top