Below is the code I'm using. When the Enter key is pressed, it intercepts (consumes) the key press and clicks an on-screen button instead. It works fine on my Motorola Android phone, with both the hardware keyboard and the on-screen keyboard. It also works fine on the Galaxy Nexus Android Virtual Device in Eclipse/ADT. But it doesn't work on the Nexus One Android Virtual Device in Eclipse/ADT. Anyone know why that might be? I'm worried that someone with a Nexus One will download my app and it won't work.
PS: I've also tried several other onKey methods (using onKeyUp, onKeyDown and ACTION_UP) and none of them worked with the Nexus One.
MyEditText.setOnKeyListener(new EditText.OnKeyListener()
{
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER))
{
MyButton.performClick();
return true;
}
return false;
}
});
MyEditText.setOnKeyListener(new EditText.OnKeyListener()
{
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if ((event.getAction() == KeyEvent.ACTION_DOWN) || (keyCode == KeyEvent.KEYCODE_ENTER))
{
MyButton.performClick();
return true;
}
return false;
}
});
Maybe you should try with ||
instead &&
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.