setMultiChoiceItems和setMessage在AlertDialog中没有“正常工作”

时间:2014-07-18 18:58:21

标签: android alertdialog android-alertdialog

我很困惑为什么我的对话框无法正常工作:

AlertDialog dialog;
final AlertDialog.Builder builder = new AlertDialog.Builder(this);  
final CharSequence[] confirmCheckbox = {"Delete the SQLite database upon exit."};
final boolean states[] = {false};

builder.setTitle("Delete Database on Exit?");
builder.setMultiChoiceItems(confirmCheckbox, states, new DialogInterface.OnMultiChoiceClickListener(){
    public void onClick(DialogInterface dialogInterface, int item, boolean state) {
    }
}).setMessage("Check the checkbox below to confirm that you wish to delete the SQLite database upon exit.\n" +
        "To cancel this action, hit the back button.")
.setPositiveButton(R.string.confirm_button_text, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        dialog.cancel();
    }
});
dialog = builder.create();
//dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); <-- This will fail. BUTTON_POSITIVE is NULL
dialog.show();

我遇到的第一个问题是没有出现任何问题。我得到了标题,它的两边各有两个奇怪的白色条,中间有一个黑色的屏幕,还有正向按钮,但是我不能引用正面按钮,因为当我这样做时,我会得到一个空指针。

我已阅读了很多tutorials,它们看起来与我的相似,但我没有运气。有什么想法吗?

0 个答案:

没有答案