how to work with device keyboard
Actually i have an editText box where i have to type a password..Now when i click the editText box an device input keyboard is open. So what i want is that when i click "done" in device input keyboard and if the password is right i have to move to the next activity..
But i dont know how to use event of device input keyboard..so please anyone suggest me..if possible with an example..I have send the snapshot to know you what exactly i want..
so as i enter password in the editText and click done in inputKeyboard it will move to next activity...here in inputKeyboard "done" is not visible but in my app it is there in m开发者_如何学编程y inputKeyboard
regards Anshuman
When you press enter in the first editText do you want it to jump to the next editText or do you just want the activity to finish? Because in your snapshot you have two editTexts and its not really logical if you want to skip the second one.
Anyway, here is an example on how to handle the enter key. pwd is an EditText in my code. In this example all I do is to hide the keyboard.
pwd.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true;
}
return false;
}
});
That could be used for the second password field you have in your snapshot. The easiest way to jump to the next one when pressing enter would to put this in the xml of your FIRST editText.
android:nextFocusDown="@+id/SecondPassword"
Where SecondPassword is your second EditText.
Simply add a listener to the EditText
's onKeyDown(int keyCode, KeyEvent event)
and check if the code is KEYCODE_ENTER
.
精彩评论