我想用简单的单选项创建对话框 . 默认情况下,不选择任何项目 . 我只想要一个OK和Cancel按钮 . 在选择项目之前,必须保持禁用“确定”按钮 . 是否有一些内置的方法,或者我必须创建自己的自定义对话框?这是我现在拥有的:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(getString(R.string.lbl_MarkReviewAs))
.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item)
{
selectedReviewStatusIndex = item;
AlertDialog alertDialog = (AlertDialog)dialog;
alertDialog.getButton(0).setEnabled(true);
}
})
.setPositiveButton(getString(R.string.lbl_ButtonOK), new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
dialog.dismiss();
}
})
.setNegativeButton(getString(R.string.lbl_ButtonCancel), new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
dialog.show();
这里的问题是dialog.getButton(AlertDialog.BUTTON_POSITIVE)返回null . 那么如何访问正面按钮?
3 回答
将侦听器设置为所选项并启用“确定”按钮
我最好的事情是继承ListActivity . 这是example .
为了使这个活动(在清单中)设置好一些Dialog(最好的选择是“@android:style / Theme.DeviceDefault.Dialog”) .
你需要显示对话框然后禁用按钮正面 .