How to handle Done button click event for Samsung Galaxy Ace
I have crea开发者_StackOverflow社区ted EditText attached setOnKeyListener
and addTextChangedListener
Using both of these I can get the text entered by the user using softkey. But If user press Done button of that soft key then I want to perform some action. I tried to handle with KeyEvent.KEYCODE_ENTER
. But the keycode is not same. How to Handle Done button click event for Samsung Galaxy Ace.
If the keycodes are not the same, give this a try to figure out what the keycode actually is.
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_DOWN)
{
Log.d("KeyCode", keyCode);
}
return false;
}
Since KEYCODE_ENTER is just a constant that represents a number, if you can find out the number that corresponds to "Done" on the Samsung Galaxy, you can handle using that number (make sure it's not zero though.)
Edit:
Also: give this a try.
event.getKeyCode() == KeyEvent.FLAG_EDITOR_ACTION)
FLAG_EDITOR_ACTION is used to identify keys with the autolabel "Done" so maybe if you handle using that instead of KEYCODE_ENTER, you'll get a positive result.
精彩评论