android - Last character gets unspanned after applying two spans on a selected text in edittext -
this problem pretty annoying iam going trace down bit bit can understand fully:-
first select last word in edit text so:-
so far simple make text bold clicking button (setting bold span) so:-
the underline default text correction in softkeyboard. reselect text:-
then when make italic same way (setting italic span pressing button) this:-
the last character gets unspanned bold .this happens in specific situation when select word , word @ end of edittext.
also found out problem occurs when spans set each char if whole word doesn't happen (for both bold , italic):-
//for each char (int = 0; < token.length(); i++) {//token word spannablestring char = (spannablestring) token.subsequence(i, + 1); char.setspan(new android.text.style.stylespan(typeface.bold), 0, char.length(), spannable.span_inclusive_exclusive); } but if whole word problem doesn't happen:-
// whole word token.setspan(new android.text.style.stylespan(typeface.bold), 0, token.length(), spannable.span_inclusive_exclusive); } but of course user can set spans char problem still relevant else no problem occurs if word not selected @ end of edit text .
i have found solution adding space char after last index before extracting selection token.
selectionstart = noteview.getselectionstart(); selectionend = noteview.getselectionend(); if(noteview.hasselection()&&selectionend==noteview.length()) { spannedstring sp=spannedstring.valueof(" "); edittext.settext(textutils.concat(edittext.gettext(),sp)); } sometimes simplest solution best solution :).




Comments
Post a Comment