make Spannable String from string and TextSpan - Android android.text

Android examples for android.text:SpannableString

Description

make Spannable String from string and TextSpan

Demo Code

import android.text.SpannableString;
import android.text.style.CharacterStyle;
import android.text.style.SubscriptSpan;
import java.util.ArrayList;
import java.util.List;

public class Main{

    public static SpannableString makeSpannableString(String text,
            List<TextSpan> textSpans) {
        text = fixupSubscripts(text, textSpans);

        SpannableString ss = new SpannableString(text);
        for (TextSpan ts : textSpans) {
            ss.setSpan(ts.style, ts.start, ts.end, 0);
        }//from   w  w w.  ja v a 2 s .c om
        return ss;
    }
    public static SpannableString makeSpannableString(String text) {
        return makeSpannableString(text, new ArrayList<TextSpan>());
    }

}

Related Tutorials