2

In Android, I am writing an app where the user enters text into an EditText view, and I would like to intercept that text before the system actually inserts it into the view, so that I can first wrap it in a SpannableText and do some decoration.

Is there any way to do this, or do I need to wait until the text is inserted, and then replace it in the afterTextChanged method (which seems like a waste of processing!)

Any ideas?

Natali
  • 2,934
  • 4
  • 39
  • 53
Victor Grazi
  • 15,563
  • 14
  • 61
  • 94

2 Answers2

0

I am sure that this can be achieved using TextWatcher. I hope this helps you even though I can't provide any examples. You can set a TextWatcher to your EditText via mEditText.addTextChangedListener(mTextWatcher).

m1ntf4n
  • 493
  • 2
  • 14
0

Maybe try to use the TextWatcher class : http://developer.android.com/reference/android/text/TextWatcher.html

Good luck !

Olivier.G
  • 143
  • 1
  • 2
  • 12
  • I know the TextWatcher can detect an insertion, but I don't see any way to get it to actually replace anything. – Victor Grazi Feb 24 '12 at 14:53
  • 1
    @VictorGrazi http://stackoverflow.com/questions/476848/android-textwatcher-aftertextchanged-vs-textwatcher-ontextchanged read both answers there – Sergey Benner Feb 24 '12 at 15:01
  • Those answers don't seem to help - seems like TextWatcher needs a hook for you to decorate text before it is actually inserted into the EditText component – Victor Grazi Feb 24 '12 at 16:44