btnNext.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int id = getCurrentFocus().getNextFocusDownId();
if(id != View.NO_ID) {
findViewById(id).requestFocus();
System.out.println("Next");
}
}
});
btnBack.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int id = getCurrentFocus().getNextFocusUpId();
if(id != View.NO_ID) {
findViewById(id).requestFocus();
System.out.println("Back");
}
}
});
This is XML where you must set the focus order
<EditText
android:id="@+id/et1"
android:nextFocusDown="@+id/et2"
android:nextFocusUp="@+id/et2"
....../>
<EditText
android:id="@+id/et2"
android:nextFocusDown="@+id/et1"
android:nextFocusUp="@+id/et1"
...../>
Edit
If you are creating a dynamic view, you should use the methods below to set the next focus.
setNextFocusDownId(id)
setNextFocusUpId(id);
source
share