我直接写了一个Demo,我运行了,符合你的需求
public class LauncherActivity extends AppCompatActivity {
EditText et_one,et_two,et_three,et_four;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
et_one=(EditText)findViewById(R.id.et_one);
et_two=(EditText)findViewById(R.id.et_two);
et_three=(EditText)findViewById(R.id.et_three);
et_four=(EditText)findViewById(R.id.et_four);
et_two.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if(TextUtils.isEmpty(s.toString())&&et_two.isFocusable()){
et_two.setFocusable(false);
et_one.setFocusable(true);
et_one.setFocusableInTouchMode(true);
et_one.requestFocus();
}
}
});
et_three.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if(TextUtils.isEmpty(s.toString())&&et_three.isFocusable()){
et_three.setFocusable(false);
et_two.setFocusable(true);
et_two.setFocusableInTouchMode(true);
et_two.requestFocus();
}
}
});
et_four.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if(TextUtils.isEmpty(s.toString())&&et_four.isFocusable()){
et_four.setFocusable(false);
et_three.setFocusable(true);
et_three.setFocusableInTouchMode(true);
et_three.requestFocus();
}
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".two.LauncherActivity"
android:orientation="vertical">
<EditText
android:id="@+id/et_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNone"
android:singleLine="true"/>
<EditText
android:id="@+id/et_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNone"
android:singleLine="true"/>
<EditText
android:id="@+id/et_three"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNone"
android:singleLine="true"/>
<EditText
android:id="@+id/et_four"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:singleLine="true"/>
</LinearLayout>