创建对话框的方法:
public void reservar(View view) {
Dialog d = new Dialog(this);
d.setContentView(R.layout.dialog_reserva);
d.show();
}
在这里,我创造了另一种方法,我不能关闭' d'对话框:
public void reservarD(View view){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setPositiveButton("Confirmar reserva", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which){
}
});
builder.show();
}
答案 0 :(得分:1)
将对话框d定义为全局变量。
Dialog d;
public void reservar(View view) {
d = new Dialog(this);
d.setContentView(R.layout.dialog_reserva);
d.show();
}
然后
public void anotherMethod(){
if(d!=null){
d.dismiss();
}
}