new to android.
How can I dismiss a dialog box when user click on Done button on the softkeyboard.
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();
}
}
});
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;
}
}