Android 警报对话框是否自行关闭?
如果用户名为空,我只想显示一个toast,但是在显示toast后对话框会被取消y?我希望它保持原样有一个解决方法可以实现。如果您正在执行的任何检查都没有通过,您只需要重新显示对话框。看看前面的答案:Android 警报对话框是否自行关闭?,android,Android,如果用户名为空,我只想显示一个toast,但是在显示toast后对话框会被取消y?我希望它保持原样有一个解决方法可以实现。如果您正在执行的任何检查都没有通过,您只需要重新显示对话框。看看前面的答案: 注意:您甚至不需要实现自己的警报对话框来执行此操作。您应该能够通过调用dialog.show()在onClick()侦听器中正确执行此操作。试一试,让我们知道它是否有效。这是警报对话框的默认行为。若你们点击肯定按钮或任何按钮,它将自动关闭。如果你不想这样做,那么做自定义对话框。 @Override
注意:您甚至不需要实现自己的警报对话框来执行此操作。您应该能够通过调用dialog.show()在onClick()侦听器中正确执行此操作。试一试,让我们知道它是否有效。这是警报对话框的默认行为。若你们点击肯定按钮或任何按钮,它将自动关闭。如果你不想这样做,那么做自定义对话框。
@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();
}