LabelExtras enables you to apply click listeners to sub-strings of a Label text.
A click on a sub-string raises an event and you can take whatever action you desire on such a click.
LabelExtras also exposes the Android Html class so you can use basic HTML formatting elements such as <b>, <i> and <u> in your Label text.
Here's the library reference:
LabelExtras
Version: 1.12
Example code to follow.
Martin.
A click on a sub-string raises an event and you can take whatever action you desire on such a click.
LabelExtras also exposes the Android Html class so you can use basic HTML formatting elements such as <b>, <i> and <u> in your Label text.
Here's the library reference:
LabelExtras
Version: 1.12
- ClickableSpan
Events:- Click (SelectionStart As Int, SelectionEnd As Int)
- Click2 (SelectionStart As Int, SelectionEnd As Int, Tag As Object)
- Initialize (EventName As String, Color As Int, UnderlineText As Boolean)
Initialize the ClickableSpan.
Color defines the color of the clickable text, pass -1 if you do not wish to change that text color.
UnderlineText defines whether the clickable text shall be underlined.
The Click(SelectionStart As Int, SelectionEnd As Int) event will be raised when this ClickableSpan is clicked. - Initialize2 (EventName As String, Color As Int, UnderlineText As Boolean, Tag As Object)
Initialize the ClickableSpan.
Color defines the color of the clickable text, pass -1 if you do not wish to change that text color.
UnderlineText defines whether the clickable text shall be underlined.
Pass any Object as the Tag and this Object will be returned to the Click2 event.
The Click2(SelectionStart As Int, SelectionEnd As Int, Tag As Object) event will be raised when this ClickableSpan is clicked. - IsInitialized As Boolean
- Html
Events:- GetDrawable (Source As String) As Object
- HandleTag (Opening As Boolean, Tag As String, SpannableStringBuilder1 As SpannableStringBuilder)
- EscapeHtml (CharSequence1 As CharSequence) As String
Returns an HTML escaped representation of the given plain text.
Only available with Android AP version 16+. - FromHtml (HtmlString As String) As CharSequence
Returns displayable styled text from the provided HTML string. - FromHtml2 (HtmlString As String, ImageGetterEventName As String, TagHandlerEventName As String) As CharSequence
Returns displayable styled text from the provided HTML string.
Using optional ImageGetter (to handle HTML IMG tags in the String) and TagHandler (to handle unrecognised tags in the String) callbacks.
The drawable returned by the ImageGetter sub has to be sized with setBounds. - ToHtml (CharSequence1 As CharSequence) As CharSequence
Returns an HTML representation of the provided Spanned text.
- LabelExtras
Methods:- SetDrawableBounds (Drawable1 As Drawable, Left As Int, Top As Int, Right As Int, Bottom As Int)
Specifies a bounding rectangle for the drawable.
Required for the Html Object ImageGetter callback. - SetMovementMethod (Label1 As TextView, MovementMethod1 As MovementMethod)
Sets the movement method (arrow key handler) to be used for this TextView.
To enable the LabelExtras click functionality you must set your Label movement method to an instance of LinkMovementMethod.
The LinkMovementMethod.GetInstance method returns the instance required.
- SetDrawableBounds (Drawable1 As Drawable, Left As Int, Top As Int, Right As Int, Bottom As Int)
- LinkMovementMethod
Methods:- GetInstance As MovementMethod
Returns an instance of the LinkMovementMethod which is required by the LabelExtras.SetMovementMethod method.
- GetInstance As MovementMethod
- SpannableStringBuilder
Methods:- Append (Text As CharSequence) As SpannableStringBuilder
- Append2 (Text As CharSequence, Start As Int, End As Int) As SpannableStringBuilder
- Append3 (Char1 As Char) As SpannableStringBuilder
- CharAt (Where As Int) As Char
- Clear
- ClearSpans
- Delete (Start As Int, End As Int) As SpannableStringBuilder
- GetChars (Start As Int, End As Int, Dest() As Char, DestOffset As Int)
- GetSpanEnd (Span1 As Object) As Int
- GetSpanFlags (Span1 As Object) As Int
- GetSpanStart (Span1 As Object) As Int
- GetStyleSpans (QueryStart As Int, QueryEnd As Int) As StyleSpan[]
- GetURLSpans (QueryStart As Int, QueryEnd As Int) As URLSpan[]
- GetUnderlineSpans (QueryStart As Int, QueryEnd As Int) As UnderlineSpan[]
- Initialize (CharSequence1 As CharSequence)
Initialize the SpannableStringBuilder with a CharSequence.
A CharSequence can be obtained using the Html.FromHtml method, a String can also be passed as a CharacterSequence. - IsInitialized As Boolean
- NextStyleSpanTransition (Start As Int, Limit As Int) As Int
Return the next offset after Start but less than or equal to Limit where a StyleSpan begins or ends. - NextURLSpanTransition (Start As Int, Limit As Int) As Int
Return the next offset after Start but less than or equal to Limit where a URLSpan begins or ends. - NextUnderlineSpanTransition (Start As Int, Limit As Int) As Int
Return the next offset after Start but less than or equal to Limit where an UnderlineSpan begins or ends. - RemoveSpan (Span1 As Object)
- Replace (Start As Int, End As Int, CharSequence1 As CharSequence) As SpannableStringBuilder
- Replace2 (Start As Int, End As Int, CharSequence1 As CharSequence, CharSequence1Start As Int, CharSequence1End As Int) As SpannableStringBuilder
- SetSpan (Span1 As Object, Start As Int, End As Int, Flags As Int)
- Length As Int [read only]
Return the number of Chars in the buffer.
- Spanned
Fields:- SPAN_EXCLUSIVE_EXCLUSIVE As Int
Constant which can be passed as the SpannableStringBuilder.SetSpan method Flags parameter.
Spans of type SPAN_EXCLUSIVE_EXCLUSIVE do not expand to include text inserted at either their starting or ending point. - SPAN_EXCLUSIVE_INCLUSIVE As Int
Constant which can be passed as the SpannableStringBuilder.SetSpan method Flags parameter.
Non-0-length spans of type SPAN_EXCLUSIVE_INCLUSIVE expand to include text inserted at their ending point but not at their starting point. - SPAN_INCLUSIVE_EXCLUSIVE As Int
Constant which can be passed as the SpannableStringBuilder.SetSpan method Flags parameter.
Non-0-length spans of type SPAN_INCLUSIVE_EXCLUSIVE expand to include text inserted at their starting point but not at their ending point. - SPAN_INCLUSIVE_INCLUSIVE As Int
Constant which can be passed as the SpannableStringBuilder.SetSpan method Flags parameter.
Spans of type SPAN_INCLUSIVE_INCLUSIVE expand to include text inserted at either their starting or ending point.
- SPAN_EXCLUSIVE_EXCLUSIVE As Int
- StyleSpan
Methods:- GetStyle As Int
Returns the Typeface style of this StyleSpan.
Typeface.STYLE_BOLD, Typeface.STYLE_ITALIC etc. - IsInitialized As Boolean
- GetStyle As Int
- URLSpan
Methods:- GetURL As String
- IsInitialized As Boolean
- UnderlineSpan
Methods:- IsInitialized As Boolean
Example code to follow.
Martin.
Attachments
Last edited: