3 回答

TA貢獻1827條經(jīng)驗 獲得超8個贊
你必須用這樣的ifand notif else語句檢查每一個:
boolean allValid = true;
if (TextUtils.isEmpty(e_Name.getText())) {
allValid = false;
// do other stuff
}
if (TextUtils.isEmpty(e_Amount.getText())) {
allValid = false;
// do other stuff
}
if (TextUtils.isEmpty(e_Description.getText())) {
allValid = false;
// do other stuff
}
// finally do what you want if allValid = false
if (!allValid) {
// your code
} else {
// all fields are valid
}

TA貢獻1788條經(jīng)驗 獲得超4個贊
你可以試試這個代碼??赡軟]有其他方法可以一次驗證所有內容。
if(TextUtils.isEmpty(e_Name.getText().toString()) ||
TextUtils.isEmpty(e_Amount.getText().toString()) ||
TextUtils.isEmpty(Display_date.getText().toString()) ||
TextUtils.isEmpty(e_Description.getText().toString()) ||
TextUtils.isEmpty(Description.getSelectedItem().toString())){
//Some edittext has no value
//Warning the field!
}else {
//Do your job here
}
添加回答
舉報