[英]How to set checkbox checked and disabled
我有以下代碼可顯示要下載的語言列表:
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 )。
你能幫我怎么做嗎?
您可以通過使用setChecked()
方法(其值為布爾值setChecked()
來選中此復選框。
例:
option1.setChecked(true);
並取消選中
option2.setChecked(false);
如果要將其設置為選中並禁用,則可以使用setEnabled(),它使用布爾值作為參數。
例。
option3.setChecked(true);
option3.setEnabled(false);
這將禁用您的復選框,甚至選中它。 我希望這可以幫到你。 謝謝。
用於設置不透明度
mSelectedItems.getBackground()。setAlpha(128);
INT的范圍是0(完全透明)到255(完全不透明)。
對於setChecked項目
mSelectedItems.setChecked(true);
禁用檢查
mSelectedItems.setEnabled(false)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.