My problem is pretty similar to the one described here. But it only appears when testing on a Android 4.2 device. On an older test device with Android 2.2 everything works quite nice.
My problem
I'm adding an ImageSpan in the middle of a TextView which shell replace one character of the TextView. At Android 4.2 no text after the ImageSpan will be shown. At Android 2.2 everything works like expected.
Code Sample
CharSequence chars = txtView.getText();
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(chars);
for (int i = 0; i < chars.length(); i++) {
int codePoint = Character.codePointAt(chars, i);
if (codePoint > 255) {
// loading the bitmap ...
ImageSpan img = new ImageSpan(context, bmp, ImageSpan.ALIGN_BASELINE);
stringBuilder.replace(i, i + 1, "");
stringBuilder.setSpan(img, i, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
txtView.setText(stringBuilder, BufferType.SPANNABLE);
Screenshots
What I've tried so far
I tried nearly any Spanned-Constant which you can add at setSpan
but nothing works on the 4.2 device.
I'm really sorry that I posted this, cause I found the answer myself.
I really thought that I tried Spanned.SPAN_INCLUSIVE_EXCLUSIVE
before, but I obviously didn't. Anyway...
stringBuilder.setSpan(img, i, i + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
works for me at Android 4.2 and Android 2.2. Hopefully this thread will help someone else in the future.