I want to detect when the soft key "done" is pressed so that when it is, it a toast message appears. I saw this post about the same question here however, I am confused about how exactly to implement the solution.
The solution provided is:
editText = (EditText) findViewById(R.id.edit_text);
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// toast message
}
return false;
}
});
my question is this:
- is editText suppose to be defined under the onCreate method?
- is the entire code suppose to be under the onCreate method?