4

I know how to take substring a normal string.

But how can I substring a spannable.

Consider following example.

This is my sample sentence.

now when I substring this i want to get the string "mple sente" just like this and with all this formatings.

In another words I want to substring a spannable not a string.

How can I do this?

SadeepDarshana
  • 1,057
  • 18
  • 34

2 Answers2

11

Spannable is a CharSequence and you should be able to use CharSequence.subSequence(int start, int end) without losing any information about the spannable

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
0

Using below code you can get substring from spannable:

SpannableString ss1 = new SpannableString(s);
        ss1.setSpan(new RelativeSizeSpan(1.1f), 0, 6, 0); // set size
        ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 6, 0);
        SpannableString ss = new SpannableString("Click here to learn more");
        ss.setSpan(clickableSpan, 0, 10, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        textview.setText(ss);

Hope it helps you.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47