[英]How do I assign a button to close the dialog?
我有一個帶有自己的標記的對話框:
@Override
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder adb = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_menu, null);
title = (TextView) view.findViewById(R.id.title);
text = (TextView) view.findViewById(R.id.textMenu);
btnOk = (Button) view.findViewById(R.id.btnOk);
btnCancel = (Button) view.findViewById(R.id.btnCancel);
title.setText(R.string.end_game);
text.setText(R.string.end_text);
btnOk.setText(R.string.btnOk);
btnOk.setOnClickListener(this);
btnCancel.setText(R.string.btnCancel);
btnCancel.setOnClickListener(this);
if (id == DIALOG_EXIT) {
title.setText(R.string.main_menu);
text.setText(R.string.menu_text);
adb.setView(view);
return adb.create();
}
if (id == DIALOG_END){
title.setText(R.string.end_game);
text.setText(R.string.end_text);
adb.setView(view);
return adb.create();
}
return super.onCreateDialog(id);
}
單擊“ btnCancel”按鈕時如何關閉對話框? 在這種情況下,方法finish()無法正常工作。
this.dismiss();
方法完成是針對活動的。 和>> 這 <<這是Dialogue的實例(針對您在對話類中的問題)。
如果您想完成“對話”中的活動,則需要將活動實例傳遞給對話類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.