Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change SpannableString content?

I'm using SpannableString in my app, I just wanted to change its content to prevent to declare new SpannableString because I want to change its content more and more again ...

this is my Code :

SpannableString span;
span = new SpannableString(getResources().getString(R.string.C1_1));
//DO STH WITH span 
span = new SpannableString(getResources().getString(R.string.Q1_1));
//DO STH DIFFERENT WITH span

how can I reference one SpannableString and just change its content?

like image 842
Shahin Ghasemi Avatar asked Sep 05 '25 18:09

Shahin Ghasemi


1 Answers

Since SpannableString is immutable object the only way to “change” value is by creating a new object.

There is a mutable SpannableStringBuilder class which might help you. You can read the documentation here.

like image 190
Gotiasits Avatar answered Sep 10 '25 11:09

Gotiasits