My users are sending unhandled exceptions to me via http://code.google.com/p/android-remote-stacktrace/
I am getting the following but have no idea what it means.
It's a known bug in the Android framework. Here's a link to the issue.
if android couldnt set the selection you do that using cursor position... i resolved the issue by putting this exactly before the crashing line
editor.setSelection(editor.getText().length(), editor.getText().length());
Its Late but yesterday i figure out this problem. The Problem is in your case is your end is before start like 7....0 which is wrong if you want to highlight a text you start should be less then your end. Check out posted example its perfectly working.
The Answer is for those Who still has this issue.
String searchText = "Your search String";
String qr_code = "Your String";
int length = searchText.length();
if (length > 0) {
//color your text here
int index = qr_code.indexOf(searchText);
SpannableString sb = new SpannableString(qr_code);
ForegroundColorSpan fcs = new ForegroundColorSpan(getResources().getColor(R.color.colorAccent));
sb.setSpan(fcs, index, (index+length), Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
holder.textViewShortCode.setText(sb);
} else {
textViewShortCode.setText(Html.fromHtml(qr_code));
}
For anyone still struggling with this issue, placing the following code in your Activity's onResume
will solve it:
textEntry.setSelection(textEntry.getText().length(), textEntry.getText().length());
I fixed it with a custom textEntry. Changed onSelectionChanged and put there the code from loopj!
My code:
@Override
protected void onSelectionChanged(int selStart, int selEnd) {
if (selStart >= 0) {
super.onSelectionChanged(selStart, selEnd);
} else {
setSelection(getText().length());
}
}