i want to do some stuff on soft keyboard enter key press. so i do code like below but it execute twice but i want that only once, so anyone know about this, if know than please give me reply for this. my code and output is like below...
Code here
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txt = (EditText)findViewById(R.id.txt);
txt.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
{
if(keyCode == KeyEvent.KEYCODE_ENTER)
{
Log.e("test","--------- on enter");
return false;
}
}
return false;
}
});
}`
Source: Tips4all, CCNA FINAL EXAM
The best way possible
ReplyDeleteif(keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN){
System.out.println("came...");
}