I have a spanned
text that I need to cast to Spannable
.
Thats what I try to do in my code:
Spannable buffer = (Spannable) text;
This code is giving me a "can't cast Spannable to Spanned".
Is it possible? if so how?
Thanks!
Add a Bulleted list in Android. With the help of BulletSpan , you can create a bullet list in your application to display some information in a short and simple way. So, in this way, we can use Spans to style the texts present in our application.
A Spannable allows to attach formatting information like bold, italic, ... to sub-sequences ("spans", thus the name) of the characters. It can be used whenever you want to represent "rich text". The Html class provides an easy way to construct such text, for example: Html.
Spannable is a Spanned , adding in the ability to modify the spans (to add or remove formatting), but not to modify the text itself. SpannedString is a concrete implementation of the Spanned interface. SpannableString is a concrete implementation of the Spannable interface.
Spans are powerful markup objects that you can use to style text at a character or paragraph level. By attaching spans to text objects, you can change text in a variety of ways, including adding color, making the text clickable, scaling the text size, and drawing text in a customized way.
You will surely get Class cast exception, because the text refers to Spanned which comes before in hierarchy to Spannable.
So, try getting the string of the text and then create a Spannable or SpannableString object.
Spannable buffer=new SpannableString(text);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With