【发布时间】:2018-06-01 01:48:48
【问题描述】:
所以我创建了一个自定义对话框,用于询问信息(如反馈。 我希望应用程序检查所有 EditTexts 是否有价值, 这是我用于打开反馈对话框的 java
private void dialog() {
myDialog.setContentView(R.layout.activity_pop_up);
editTextEmailValue = (EditText) myDialog.findViewById(R.id.editTextEmail);
editTextMessageValue = (EditText) myDialog.findViewById(R.id.editTextMessage);
editTextNumeValue = (EditText) myDialog.findViewById(R.id.editTextNume);
Button btnSend = (Button) myDialog.findViewById(R.id.sendBtn);
Button btnClose = (Button) myDialog.findViewById(R.id.close);
btnSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//This is what I've tried (the check method is bewlow)
if (check() > 1) {
editTextNumeValue.setError("Obligatoriu!");
editTextMessageValue.setError("Obligatoriu!");
editTextEmailValue.setError("Obligatoriu!");
} else if (check() == 0) {
sendMail();
}
}
});
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myDialog.dismiss();
}
});
myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
myDialog.show();
}
这是我的检查方法:
private int check() {
int counter = 0;
if (editTextEmailValue.equals("")) {
editTextEmailValue.setError("Obligatoriu!");
counter++;
} else if (editTextMessageValue.equals("")) {
counter++;
editTextMessageValue.setError("Obligatoriu!");
} else if (editTextNumeValue.equals("")) {
editTextNumeValue.setError("Obligatoriu!");
counter++;
}
return (counter);
}
当我按下发送按钮(用于电子邮件)时,它进入检查方法并以 0 1 2 3 退出(我只有 3 个 textView),但是当它检查 btnSend.onClickListener 时,如果满足条件,它仍然发送邮件,所以我可以从检查方法中说,计数器的值一直为 0,你能帮我吗?
【问题讨论】:
标签: java android popup conditional-statements