0

I read flags parameter in google docs, but I can't find what exactly it's doing. For example in below code:

SpannableStringBuilder builder1 = new SpannableStringBuilder();
builder1.append("hi");
builder1.append("this is test");
builder1.setSpan(new ForegroundColorSpan(Color.RED), 0, 7, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
myTextView.setText(builder1);

There is no difference if you change 4th parameter and set variables like this: Spanned.SPAN_INCLUSIVE_INCLUSIVE,Spanned.SPAN_INCLUSIVE_EXCLUSIVE,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE.

There is no difference in result.

But when run this code:

SpannableStringBuilder builder1 = new SpannableStringBuilder();
builder1.append("hi");
builder1.append("this is test");
builder1.setSpan(new ForegroundColorSpan(Color.RED), 0, 7, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

SpannableStringBuilder builder2 = new SpannableStringBuilder();
builder1.append("second test this is going to be different");
builder1.setSpan(new BackgroundColorSpan(Color.BLUE), 10, 15, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

SpannableStringBuilder all = new SpannableStringBuilder();
all.append(builder2);
all.insert(0, "\n");
all.insert(0, builder1);

You get different results based on 4th parameter that you pass to builder1.setSpan

Can somebody explains why this happens?

Hojjat
  • 815
  • 1
  • 10
  • 25

1 Answers1

0

The flag is set on spans that are being used to apply temporary styling information on the composing text of an input method, so that they can be found and removed when the composing text is being replaced

  • I can't understand what you mean? Could you give an example? – Hojjat Dec 19 '16 at 11:01
  • For example like you are trying to change the text color dynamically so Spannable string performs temporary styling once your styling is done it will need some key to remove it and that flag acts as key – Deepali-Systematix Dec 19 '16 at 11:05