sparrkli
sparrkli

Reputation: 671

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

Upvotes: 3

Views: 2278

Answers (1)

sparrkli
sparrkli

Reputation: 671

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

Upvotes: 6

Related Questions