UMAR UMAR - 5 months ago 19
Android Question

Android keyboard next button issue on EditText

I am facing an issue i have username & password fields on activity, now when i click on username keyboard appears but no next button on it and i cannot move to next Edittext control through keyboard in this case, keyboard displays enter button in it as attached in screenshot which increases its height,

any one guide me what is the solution to this problem(to display next button on edittext)?

any help would be appreciated
enter image description here

My Code

txtUserid = (EditText)findViewById(R.id.txtUserID);
txtUserPasword = (EditText)findViewById(R.id.txtPassword);

txtUserid.setNextFocusDownId(R.id.txtPassword);
txtUserPasword.setNextFocusDownId(R.id.btnLogin);

Answer

add this lines below your lines of code you provided:

txtUserid.setOnKeyListener(new OnKeyListener() {

    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 Enter key press
                txtUserid.clearFocus();
                txtUserPasword.requestFocus();
                return true;
          }
          return false;
    }
});

txtUserPasword.setOnKeyListener(new OnKeyListener() {

    public boolean onKey(View v, int keyCode, KeyEvent event) {

          if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER))
          {
                 // Perform action on Enter key press
                 // check for username - password correctness here
                 return true;
          }
          return false;
    }
});