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?<
This is an old issue that seems not to be solved yet. There's a workaround for these cases. Simply take the EditText (or whatever View you might be needing this and assign it a onEditorActionListener, like this:
final EditText editor = (EditText) findViewById(R.id.myEditText);
editor.setOnEditorActionListener(EnterOnText);
Now define the EnterOnText implementation like this:
TextView.OnEditorActionListener EnterOnText = new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
final String msg = view.getText().toString();
if (!msg.isEmpty()) {
// Do whatever you need here
...
}
}
return true;
}
};
Now, simply change the layout's imeOptions attribute to:
android:imeOptions="actionGo"
That will, oppositely, probably make your emulator's enter key not work, but will (should) do on all physical devices.