如何在運行時更改自定義AlertDialog
的佈局(onclicking_positive_button)。在運行時單擊肯定按鈕時更改警報對話框佈局
舉例:創建AlertDialog
與layout_1肯定按鈕變化onClick
到layout_2
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
final LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.layout_1, null);
dialogBuilder.setView(dialogView);
final AlertDialog finalAlertDialog = alertDialog;
dialogBuilder.setPositiveButton("time",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
View view= inflater.inflate(R.layout.layout_2,null);
finalAlertDialog.setContentView(view);
finalAlertDialog.show();
}
});
dialogBuilder.setNegativeButton("cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog = dialogBuilder.create();
alertDialog.show();
finalAlertDialog.show前添加dialog.dismiss()()XML文件; –