Thursday 7 July 2011

Detecting done / enter on an EditText

Had some trouble detecting DONE / ACTION_FINISHED / Pressing Enter - They can all fire a bit differently on the emulator and on different phones.

stackoverflow comes to the rescue again!


myEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH ||
actionId == EditorInfo.IME_ACTION_DONE ||
event.getAction() == KeyEvent.ACTION_DOWN &&
event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
// Do something
}
return false;
});

No comments:

Post a Comment