Edit Text key listener Edit Text key listener android android

Edit Text key listener


I'm probably late now but, this is the way I do it:

public class MyActivity extends Activity{    private KeyListener listener;    private EditText editText;    public void onCreate(...)    {        editText = ... // Get EditText from somewhere        listener = editText.getKeyListener(); // Save the default KeyListener!!!        editText.setKeyListener(null); // Disable input    }    // When you click your button, restore the default KeyListener    public void buttonClickHandler(...)    {        editText.setKeyListener(listener);    }}

Basically, you first save the EditText's default KeyListener before you call setKeyListener(null). Then, when you click your button, you call setKeyListener again, passing the default listener you previously saved.


You can use this :

// When you click your button, restore the default KeyListenerpublic void buttonClickHandler(...){    editText.setKeyListener(new EditText(getApplicationContext()).getKeyListener());}


its bug in android See here Bugs.

But in xml file you can do it.Using android:editable="false"

<EditText    android:id="@+id/editText1"    android:layout_width="wrap_content"    android:layout_height="wrap_content"     android:editable="false" <<<<<<<</EditText>