这里我要显示两个AlertDialogs。单击第一个AlertDialog的正按钮后,将显示第二个AlertDialog。
MainActivity.class
public class MainActivity extends AppCompatActivity {
public static final String ACTION_NEXT = "Next";
public static final String ACTION_DONE = "Done";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupSecretFields(this, "Configuration", "Please Enter Password", ACTION_NEXT);
}
private void setupSecretFields(final Context context, final String title, final String hint, final String button) {
final AppCompatEditText appCompatEditText = new AppCompatEditText(context);
appCompatEditText.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
appCompatEditText.setHint(hint);
appCompatEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
final LinearLayout linearLayout = new LinearLayout(context);
linearLayout.addView(appCompatEditText);
linearLayout.setPadding(40, 30, 40, 20);
linearLayout.setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT));
final AlertDialog builder = new AlertDialog.Builder(context, R.style.CustomAlert)
.setPositiveButton(button, null)
.setNegativeButton("Cancel", null)
.setView(linearLayout)
.setCancelable(false)
.create();
builder.show();
builder.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (button.equals(ACTION_NEXT)) {
if (appCompatEditText.getText().toString().trim().equals("1234")) {
builder.dismiss();
//Showing another AlertDialog
setupSecretFields(context, "Configuration", "Please Enter Api Url", ACTION_DONE);
} else {
appCompatEditText.setError("Incorrect Password! Please try again");
}
} else {
Toast.makeText(context, "Application Will Restart...", Toast.LENGTH_LONG).show();
}
}
});
}
}
First Dialog工作正常,但它没有显示另一个AlertDialog。不知道它有什么问题。请帮助。
答案 0 :(得分:0)
变化:
jQuery(document).ready(function($) {
$("#logout").click(function () {
<% session[:login] = 0 %>
alert(<%= session[:login] %>);
location.reload();
});
});
为:
final AlertDialog builder = new AlertDialog.Builder(context, R.style.CustomAlert)
.setPositiveButton(button, null)
.setNegativeButton("Cancel", null)
.setView(linearLayout)
.setCancelable(false)
.create();
builder.show();
应该帮助你。