警报对话框中的android复选框未显示
您好,我正在尝试显示一个带有复选框的警报对话框,以便允许用户选择“不再显示此对话框”选项。对话框正在显示,但复选框未显示。这是我的密码:警报对话框中的android复选框未显示,android,checkbox,android-alertdialog,Android,Checkbox,Android Alertdialog,您好,我正在尝试显示一个带有复选框的警报对话框,以便允许用户选择“不再显示此对话框”选项。对话框正在显示,但复选框未显示。这是我的密码: AlertDialog.Builder dialogBack; dialogBack = new AlertDialog.Builder(this); dialogBack.setTitle(context.getString(R.string.msg_attention)); dialogBack.setMessage(context.getStrin
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);
您的
items
数组应使用整数id引用,如R.array.items
至少根据上面的例子
这将解释该元素及其关联的复选框没有显示。我只是很惊讶你的IDE没有捕捉到这一点 我的想法是删除
dialogBack.setMessage(context.getString(R.string.msg_photo_caution))代码>并且您的代码运行良好。似乎无法同时设置消息
和多选项项
。您可以通过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);
我已经更改了这一行的dialogBack.setMultiChoiceItems(R.array.string\u array\u name,null,…但这并没有解决我的问题。是的,我省略了消息,现在显示了复选框。非常感谢。@adrian4aes不客气。另外,我还添加了一些代码来更新我的答案