0

I have a EditText. When I focus on it, all of the text is selected. When the user enters a character, the previous text (selected text) is removed and the new character is inserted in the EditText.

I want to prevent removing the selected text when the user inserts character '='.

How can I do that?

Bob
  • 22,810
  • 38
  • 143
  • 225
  • I'm not aware of the Android OS default behaviors but a simple and generic way would be to keep the original value of the TextView on focus event and rewrite it back if the newly entered value is "=". – Mikayil Abdullayev Jan 28 '13 at 11:17
  • It sounds like job for TextWatcher.. Please use http://developer.android.com/reference/android/text/TextWatcher.html by http://developer.android.com/reference/android/widget/TextView.html#addTextChangedListener%28android.text.TextWatcher%29 – deadfish Jan 28 '13 at 11:17

1 Answers1

1

Use a textwatcher with your EditText , it has three methods

afterTextChanged(Editable s)
beforeTextChanged(CharSequence s, int start, int count, int after)
onTextChanged(CharSequence s, int start, int before, int count)

Use beforeTextChanged and check if the special character( = or whatever) has been inserted , keep old text

http://developer.android.com/reference/android/text/TextWatcher.html

baboo
  • 1,983
  • 17
  • 23