How to enable the button next to Android to go to a specific field?

Asked

Viewed 928 times

0

I have a form with 4 Edittexts and when I finished filling the first one and clicking the next I needed to go to the third field. Does anyone know how to set this to the next go to a specific Edittext? Thanks in advance!

  • Meuedittext.requestFocus() does not serve?

2 answers

1

I believe the attribute nextFocusDown solves your problem, example:

<EditText
    ... <!-- Demais atributos -->
    android:nextFocusDown="@+id/proximo_edit_text" />

<EditText
    android:id="@id/proximo_edit_text"
    .... <!-- Demais atributos -->
    />

When the user clicks on the "Next" of the physical keyboard, it will shift the focus to the EditText whose id be the value of nextFocusDown.

I think this official documentation about Supporting Keyboard Navigation can help you with other questions.

0

This solution works (no need to add android:focusable="true" android:focusableInTouchMode="true"):

final EditText userEditText = (EditText)findViewById(R.id.userEditText);

userEditText.setOnFocusChangeListener(new OnFocusChangeListener() {

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if(!hasFocus){
            Log.i(TAG, "userEditText lost focus");
            if(null == m_requestFocus){
                m_userName = userEditText.getText().toString();
                if(m_userName.length() < 6){
                    m_signUpText.setText("Username should have at least 6 characters");
                    m_requestFocus = userEditText;
                }
                else{
                    checkUserNameExists();
                }
            }
        }
        else{
            if(null != m_requestFocus & m_requestFocus != userEditText){
                v.clearFocus();
                m_requestFocus.requestFocus();
                m_requestFocus = null;
            }
        }
    }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.