Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorect line wrapping when using bulletspan

I'm trying to solve my problem for 2 days now but without any success.

The problem is: when I set BulletSpan to text and then display it in EditText everything works fine until I start typing in another text. When the text is wrapped at the end of the screen, the indentation works but the cursor is pointing off the actual position and also some characters from previous line are added after the cursor. To better illustrate this problem see the attached image.

Span Error

Also is worth mentioning that this happen only when I type in text, when I'm setting the text in the source and the text is too long to be only on one line the wrapping works fine and no extra characters are added nor the cursor position is wrong.

Also I tried LeadingMarginSpan.Standart and the behaviour was the same.

In code I'm setting the start mark:

private void handleListStart(SpannableStringBuilder text) {
    int len = text.length();
    text.setSpan(new ListItem(), len, len, Spannable.SPAN_MARK_MARK);
}

Then setting the span:

private void handleListEnd(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, ListItem.class);
    int where = text.getSpanStart(obj);

    text.removeSpan(obj);

    if (where != len) {
        text.setSpan(new BulletSpan(listIndent * 15), where, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    }
}

I'm getting the data from xml file.

Thanks for any help

EDIT: I forget to add that I have tried this on Android 4.1 and 4.4 and both behaved the same

like image 272
Jan Avatar asked Feb 11 '14 13:02

Jan


1 Answers

This issue happens when your bulletspan-style characters come to a new line.

You can listen when the lines increase, then you can clear the bulletspan and set a new bulletspan again.

The solutiion above works perfectly for me.

like image 71
QuinnChen Avatar answered Nov 08 '22 14:11

QuinnChen