I have a form with 4 EditTexts and when I finish filling the first one and click the next one I need to go to the third field. Does anyone know how to set this to the next go to a specific EditText? Thank you in advance!
I have a form with 4 EditTexts and when I finish filling the first one and click the next one I need to go to the third field. Does anyone know how to set this to the next go to a specific EditText? Thank you in advance!
I believe that the nextFocusDown
attribute solves your problem, for 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 switch the focus to EditText
whose id
is the value of nextFocusDown
.
I think this official documentation on Supporting Keyboard Navigation can help you with other issues.
/ p>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;
}
}
}
});