Can someone please provide a solution to get a working listener for the soft-keyboard DONE
button, and/or explain what I\'m doing wrong in my current approach?<
try this code this is a code with 2 fields in which i have user time feature. in first one keyboard shows next button and in second one soft keypad shows done option and on done option i hide the soft keypad.
below is the xml file code.
now below is the java code: for hiding soft keypad on next and same can be performed for done option as well.
this code add in onCreate() of your class.
EditText first_txt = (EditText) findViewById(R.id.txt1);
EditText second_txt = (EditText) findViewById(R.id.txt2);
first_txt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true; // Focus will do whatever you put in the logic.
}
return false; // Focus will change according to the actionId
}
});
second_txt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true; // Focus will do whatever you put in the logic.
}
return false; // Focus will change according to the actionId
}
});
This code works for , hope it helps you out!