the two events can be detected separately. For the first case, we must put a listener that detects the pressure of buttons and with the validate the button of done to perform an action. This is done as follows
final EditText edittext = (EditText) findViewById(R.id.edittext);
edittext.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
//aqui iria tu codigo al presionar el boton enter o done
return true;
}
return false;
}
});
For the second question, it occurs to me to listen when the edittext in question loses focus. for that we use the following code
EditText txtEdit = (EditText) findViewById(R.id.edittxt);
txtEdit.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
// code to execute when EditText loses focus
}
}
});
my sources were taken from the following post
link
link