我有我自己的標記一個對話框:如何分配一個按鈕來關閉對話框?
@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()方法無法正常工作。
顯示你初始化這個對話框的代碼部分 –
以及如何初始化它?我只是調用一個方法showDialog(...); – Tenday
謝謝,我發現:dialog = adb.create(); – Tenday