我有这个问题中讨论的相同问题
问题是当用户输入无效数据并单击提交按钮时,会打开失败的警报对话框。我在失败的警报对话框上有一个按钮(继续),单击它后我写了 dialog.dismiss(); 使其消失,以便用户可以重新检查数据并进行修改。但问题是在重新检查和修改数据时,如果他改变了方向,那么即使没有单击提交按钮,也会再次弹出失败的警报对话框。请建议。
这是我的代码,请帮助我....
final EditText Name = (EditText) findViewById(R.id.editText1);
final EditText Phone = (EditText) findViewById(R.id.editText2);
final EditText Email = (EditText) findViewById(R.id.editText3);
final EditText Message = (EditText) findViewById(R.id.editText4);
final AlertDialog alertDialog = new AlertDialog.Builder(Contact.this)
.create();
alertDialog.setButton("Continue..",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// here you can add functions
alertDialog.dismiss();
}
});
Submit = (ImageButton) findViewById(R.id.bSubmit);
Submit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (Name.getText().toString().length() > 0) {
if (Phone.getText().toString().matches("^[0-9]{1,10}$")) {
if (Email.getText().toString()
.matches("[a-zA-Z0-9._-]+@[a-z]+.[a-z]+")) {
if (Message.getText().toString().length() > 10) {
//Calling async class and sending data to server
} else
alertDialog.setMessage("msg is tooo short...");
alertDialog.show();
} else
alertDialog.setMessage("Invalid email ID");
alertDialog.show();
} else
alertDialog.setMessage("Invalid Number...");
alertDialog.show();
} else
alertDialog.setMessage("Enter the Name...!");
alertDialog.show();
}
});