Reputation: 809
I referred this link to listen the android EditText finish typing event. But from this reference i am getting the Enter key pressed event only. I need to listen an event when user closes keybord after finishing the typing and also when user presses Next. is there any way to listen theses events in android.
Upvotes: 1
Views: 3521
Reputation: 809
finally i got the answer for Next/Done/search AND enter key press like this
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(event !=null){
if(actionId == EditorInfo.IME_ACTION_SEARCH ||
actionId == EditorInfo.IME_ACTION_NEXT ||
actionId == EditorInfo.IME_ACTION_DONE ||
event.getAction() == KeyEvent.ACTION_DOWN &&
event.getKeyCode() == KeyEvent.KEYCODE_ENTER){
if (!event.isShiftPressed()) {
Log.e("", "FINISHED Typing : "+v.getText().toString());
return true; // consume.
}
}
}
else{
if(actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE){
Log.e("", "Next/Done/Search Pressed");
return true;
}
}
return false;
}
also for the Keypad dismiss i customized the editText and override the method onKeyPreIme into that. Whenever i need the edittext , i am using this edittext. this solved my issue.
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (event.getAction()!=KeyEvent.ACTION_DOWN){
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
dispatchKeyEvent(event);
//do whatever you want to do here, when keypad dismiss on EditText
return false;
}
}
return super.onKeyPreIme(keyCode, event);
}
Upvotes: 3