您好我正在尝试显示带有复选框的警告对话框,以便允许用户选择“不再显示此对话框”选项。对话框正在显示,但复选框没有显示。这是我的代码:
AlertDialog.Builder dialogBack;
dialogBack = new AlertDialog.Builder(this);
dialogBack.setTitle(context.getString(R.string.msg_attention));
dialogBack.setMessage(context.getString(R.string.msg_photo_caution));
dialogBack.setCancelable(false);
dialogBack.setPositiveButton(context.getString(R.string.confirm_continue),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogBack, int which) {
dialogBack.dismiss();
beginTakeSupervisorPhoto();
}
});
dialogBack.setNegativeButton(context.getString(R.string.confirm_cancel),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogBack, int which) {
dialogBack.dismiss();
}
});
final CharSequence[] items = {context.getString(R.string.msg_dont_show_again)};
dialogBack.setMultiChoiceItems(items, null,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int indexSelected,boolean isChecked) {
Log.e("ListaClientesActivity.java","isChecked: "+isChecked);
if (isChecked) {
showPhotoWarning = false;
dataUtil.putBoolean(Constantes.SHOW_PHOTO_WARNING, false);
}else{
showPhotoWarning = true;
dataUtil.putBoolean(Constantes.SHOW_PHOTO_WARNING, true);
}
dataUtil.savePreferences();
}
});
dialogBack.create().show();
这很奇怪,因为当我使用文本视图进行对话时,它对我有用:
dialogBack.setView(myMsg);
答案 0 :(得分:4)
我的想法是删除dialogBack.setMessage(context.getString(R.string.msg_photo_caution));
,您的代码运行良好。您似乎无法同时设置Message
和MultiChoiceItems
。您可以将消息放入标题中,或者通过setView
添加您自己的布局到对话框
修改强>
设置视图的代码:
TextView message = new TextView(context);
message.setText(context.getString(R.string.msg_photo_caution));
CheckBox do_not_show_this_again = new CheckBox(context);
do_not_show_this_again.setText(context.getString(R.string.msg_dont_show_again));
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(message);
layout.addView(do_not_show_this_again);
dialogBack.setView(layout);
答案 1 :(得分:1)