我正在尝试在提交之前验证表单中的用户输入,但它允许所有空字段通过...任何想法?我试过“”而不是null ......
public void onClick(View v) {
EditText agencyname = (EditText) findViewById(R.id.agencyname);
String agency = agencyname.getText().toString();
EditText firstname = (EditText) findViewById(R.id.firstname);
String first = firstname.getText().toString();
EditText lastname = (EditText) findViewById(R.id.lastname);
String last = lastname.getText().toString();
EditText phone = (EditText) findViewById(R.id.phone);
String agencyphone = phone.getText().toString();
EditText email = (EditText) findViewById(R.id.email);
String agencyemail = email.getText().toString();
if(agency != null || first != null || last != null || agencyphone != null || agencyemail != null){
Intent i = new Intent();
i.setClassName("android.com.smartchoice", "android.com.smartchoice.AgencyRecieve");
i.putExtra("agencyname", agency);
i.putExtra("phone", agencyphone);
i.putExtra("email", agencyemail);
i.putExtra("firstname", first);
i.putExtra("lastname", last);
startActivity(i);
}
else
{
Toast.makeText(NewAgencyActivity.this, "Must Input All Fields", Toast.LENGTH_LONG).show();
};
}
答案 0 :(得分:0)
agency.isEmpty()
等检查空字符串(""
)。&&
)代替或(||
)。