I am created an app which toast some text when user click on android keyboard's ENTER key but its working on my desktop keyboard means when i click on desktop keyboard's enter key its making toast.
So what could i do for android keyboard's enter key????
HERE is code:
public class MainActivity extends AppCompatActivity implements View.OnKeyListener{
EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText=(EditText)findViewById(R.id.editText);
editText.setOnKeyListener(this);
}
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_ENTER){
Toast.makeText(this,editText.getText().toString()+"Enter Pressed",Toast.LENGTH_LONG).show();
return true;
}
return false;
}
}
Try using this: Filter your action first using
KeyEvent.ACTION_DOWNEDIT
use an
setOnEditorActionListeneron yourEdittextMake sure in XMl you had: