You are setting a new onKeyListener
to edittext1 everytime a key is pressed in edittext... is that actually what you want to do?
The code you've got to detect when the enter key is pressed seems fine. You will need to add the following code to close the keyboard and do a toast.
editText.setOnEditorActionListener(new TextView.OnEditorActionListener(){
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN)
&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))
{
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
Toast.makeText(MyAndroidAppActivity.this, "My message", Toast.LENGTH_SHORT).show();
}
}
}