Android studio java-app: When typing more than one bold letter, the previous bold letter loses its bold formatting. Can anyone explain why? I've looked at all the similar questions but I can't find the answer.
editText.addTextChangedListener(new TextWatcher() {
boolean isBoldInProgress = boldIsOn;
int ii;
@Override
public void beforeTextChanged(CharSequence edittextBeforeChange, int startOfChange, int NumberReplaced, int NumberOfInserted) {
isBoldInProgress = boldIsOn && NumberOfInserted > 0;
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable editable) {
if (isBoldInProgress) {
ii = editText.getSelectionEnd();
// Apply bold to character before the cursor
editable.setSpan(new StyleSpan(Typeface.BOLD), ii - 1, ii, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
isBoldInProgress = false;
}
}
});