0

new to android.

How can I dismiss a dialog box when user click on Done button on the softkeyboard.

Daniel
  • 1

2 Answers2

1

For your EditText do : edt.setOnKeyListener(this);

and in your Activity do :

@Override
public boolean onKey(View v, int keyCode, KeyEvent event){
    if(keyCode == event.KEYCODE_ENTER){
        dismissDialog();
    }
return true;
}

OR

    edt.setOnKeyListener(new OnKeyListener(){
    @Override
    void onKey(View v, int keyCode, KeyEvent event){
        if(keyCode == event.KEYCODE_ENTER){
            dismissDialog();
        }
    }
    });
Logic
  • 2,230
  • 2
  • 24
  • 41
0

You can use below function to get IME_ACTION for done button.

private class OnMyEditorActionListener implements OnEditorActionListener {
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            dialog.dismiss();
            return true;
        }
        return false;
    }
}
vijaypalod
  • 398
  • 4
  • 15