當你在第一個editText中按回車你想讓它跳到下一個editText或者你只是想完成活動?因爲在你的快照中你有兩個editTexts,如果你想跳過第二個editText,那麼它就不合邏輯了。
無論如何,這裏是一個關於如何處理回車鍵的例子。 pwd是我的代碼中的EditText。在這個例子中,我所做的就是隱藏鍵盤。
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;
}
});
這可以用於快照中的第二個密碼字段。 按enter鍵跳轉到下一個最簡單的方法是將其放入FIRST editText的xml中。
android:nextFocusDown="@+id/SecondPassword"
其中SecondPassword是您的第二個EditText。