Search code examples
androidfocusandroid-edittextonkeypress

Change focus of edittext on Enter pressed_android


So i want to switch focus to edittext karticeEdit if in edittext gotovinaEdit enter is pressed. this is my code so far, but it is not working

 final EditText gotovinaEdit = (EditText) vieww.findViewById(R.id.gotovinaEdit);
 final EditText karticeEdit = (EditText) vieww.findViewById(R.id.karticeEdit);
 gotovinaEdit.setOnKeyListener(new View.OnKeyListener() {
                @Override
                public boolean onKey(View view, int i, KeyEvent keyEvent) {
                    if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (i == KeyEvent.KEYCODE_ENTER)) {
                        gotovinaEdit.clearFocus();
                        karticeEdit.requestFocus();
                        return true;
                    }
                    return false;
                }
            });

EDIT: figured it out, just had to add android:singleLine="true", hope this helps someone


Solution

  • Figured it out, just had to add android:singleLine="true", hope this helps someone