我有两个 EditText
,例如 editText1 和 editText2。
我正在从 EditText
获取输入到 name1 和 name2。
现在我想在单击“确定”按钮之前验证 EditText
不为空。
为此,我使用了:
if(editText1==NULL && editText2==NULL) {
textView.setText("please enter Names");
} else {
other code;
}
但它没有验证,并且在 EditText
为空的情况下,单击“确定”按钮后会显示结果。
我也尝试过这种方式:
if(name1==NULL && name2==NULL) {
textView.setText("please enter Names");
} else {
other code;
}
要做什么?
最佳答案
试试这个:
if(editText1.getText().toString().trim().equals("")
&& editText2.getText().toString().trim().equals(""))
{
textView.setText("Please enter Names");
}
else
{
// other code
}
关于java - Android EditText 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18050412/