这是我的代码希望它足够清楚使用此代码我正在尝试使用 isEnabled 函数来检查我的 EditText 字段是否有值,如果它们没有值,则必须禁用提交按钮,否则如果它们都有值按钮必须启用,以便用户可以导航到新活动
public class RegisterAccountActivity extends AppCompatActivity {
//Declaring Button and EditText
private Button submit;
private EditText name;
private EditText surname;
private EditText email;
private EditText phoneNumber;
private EditText address;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register_account);
submit = (Button) findViewById(R.id.btnSubmitPersonalDetails);
name = (EditText)findViewById(R.id.edtName);
surname = (EditText)findViewById(R.id.edtSurname);
email = (EditText)findViewById(R.id.edtEmail);
phoneNumber = (EditText)findViewById(R.id.edtPhoneNumber);
address = (EditText)[findViewById][1](R.id.edtPostalAddress);
//Calling the checking fields method
checkFields();
}
//Function to disable button if fields doesn't have value
public void checkFields() {
//Here i am checking if EditText have values
if (!submit.getText().toString().isEmpty() &&
!name.getText().toString().isEmpty() &&
!surname.getText().toString().isEmpty() &&
!email.getText().toString().isEmpty() &&
!phoneNumber.getText().toString().isEmpty() &&
!address.getText().toString().isEmpty()) {
submit.setEnabled(true);
} else {
submit.setEnabled(false);
}
}
[查找表格的附件图像]