Pregunta

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?

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top