@Override
protected Dialog onCreateDialog(int id) {
LayoutInflater factory = LayoutInflater.from(GmailFetchActivity.this);
final View textEntryView = factory.inflate(R.layout.alertdialog_gmail, null);
final EditText username = (EditText) textEntryView.findViewById(R.id.edit_username);
editxt_pass = (EditText) textEntryView.findViewById(R.id.edit_password);
final CheckBox remember = (CheckBox) textEntryView.findViewById(R.id.checkBox_remember);
username.setText(myPrefs.getString("username", ""));
editxt_pass.setText(myPrefs.getString("password", ""));
AlertDialog.Builder alert=new AlertDialog.Builder(this);
alert.setTitle("Gmail login");
alert.setView(textEntryView);
alert.setPositiveButton("Login", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if(username.getText().toString().trim().equalsIgnoreCase(""))
{
}
else{
if(isNetworkAvailable()){
String user=username.getText().toString();
String pass=editxt_pass.getText().toString();
if(remember.isChecked()){
prefsEditor.putString("username",user);
prefsEditor.putString("password",pass);
prefsEditor.commit();
}
else{
prefsEditor.putString("username","");
prefsEditor.putString("password","");
prefsEditor.commit();
}
progressHrz.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressHrz.setMessage("Fetching attachment's list");
progressHrz.setCancelable(true);
progressHrz.show();
new FetchGmail().execute(user+"@gmail.com",pass);
}
else
Toast.makeText(getApplicationContext(), "No internet access", Toast.LENGTH_LONG).show();
}
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
finish();
}
}) ;
return alert.create();
}
如果用户名是空的,我只想展示一个祝酒词,但是在显示toast y之后对话框被解除了?我希望它保持原样
答案 0 :(得分:0)
你可以实施一项工作。如果您执行的任何检查未通过,您只需要重新显示该对话框。看一下之前的答案:Is there a way prevent AlertDialog from closing with invalid inputs?
注意:您甚至可能不需要实现自己的警报对话框来执行此操作。您应该可以通过调用dialog.show()在onClick()侦听器中执行此操作。试一试,让我们知道它是否有效。