-1

In http://developer.android.com/reference/android/text/TextWatcher.html, it says:

you can use setSpan(Object, int, int, int) in onTextChanged(CharSequence, int, int, int) to mark your place and then look up from here where the span ended up.

But how do I actually implement that?

Yifan Hong
  • 41
  • 6

1 Answers1

0

This is how to do it:

    this.addTextChangedListener(new TextWatcher() {
        Object markup = new Object();
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            EditText.this.getEditableText().setSpan(markup, start, start + count, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        public void afterTextChanged(Editable editable) {
            Log.v("TAG", "" + editable.getSpanStart(markup) + " " + editable.getSpanEnd(markup));
        }
    });
Yifan Hong
  • 41
  • 6