Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a spanned to spannable

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!

like image 999
roiberg Avatar asked Jul 02 '13 07:07

roiberg


People also ask

How do you make Spannable strings?

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.

What is a difference between Spannable and string?

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.

What is a Spannable?

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.

What is spanned text?

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.


1 Answers

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);
like image 87
Shail Adi Avatar answered Sep 26 '22 15:09

Shail Adi