【发布时间】:2016-03-29 14:36:52
【问题描述】:
我有这个代码来显示下载的语言列表:
public void onCreateDialog(ArrayList<String>fullLangArray, final ArrayList<String>codeLangArray) {
final String[] items = fullLangArray.toArray(new String[fullLangArray.size()]);
final ArrayList mSelectedItems = new ArrayList();
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
// Set the dialog title
builder.setTitle("Updates...")
.setMultiChoiceItems(items, null,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int indexSelected,
boolean isChecked) {
if (isChecked) {
mSelectedItems.add(Utils.SERVER_ADDRESS + "/" + codeLangArray.get(indexSelected) + ".zip");
} else if (mSelectedItems.contains(indexSelected)) {
mSelectedItems.remove(Integer.valueOf(indexSelected));
}
}
})
.setPositiveButton("Download", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
DownloadTask downloadTask = new DownloadTask(MainActivity.this);
downloadTask.execute(mSelectedItems.toString());
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
我想在加载 AlertDialog 时选中复选框中的一项并像照片中一样“禁用”(选项 3)。
你能帮我怎么做吗?
【问题讨论】:
-
只是调用 checkBox.setChecked(true/false) 和 checkbox.setEnabled(true/false).....还是我误解了问题?
-
你可以使用 your_checkbox.setChecked(true);your_checkbox.setEnabled(false);
-
@Opiatefuchs,已编辑描述。
-
所以你只希望框有点透明而不是文本?
-
@Opiatefuchs,透明与否无关紧要,用户无法取消选中该项目。始终应检查该项目。
标签: java android android-alertdialog android-checkbox