0
我想弄清楚如何以編程方式選中我的複選框對話框代碼,我已經設置了我的複選框。複選框對話框以編程方式選擇
我將如何以編程方式從我的onClick方法下方切換我的複選框。
如果有人可以看看我的代碼到目前爲止,並給我一些指導,那會很好。
代碼:
AlertDialog dialog;
final CharSequence[] items = { "All listings", "Buy it now",
"Auction", "Nearest first" };
final ArrayList<Integer> seletedItems = new ArrayList<Integer>();
final SharedPreferences shfObject = getActivity()
.getSharedPreferences("NAME", Context.MODE_PRIVATE);
final SharedPreferences.Editor shfEditorObject = shfObject.edit();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Filter");
builder.setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog,
final int indexSelected, boolean isChecked) {
if (isChecked) {
}
}
})
// Set the action buttons
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
// Your code when user clicked on Cancel
}
});
dialog = builder.create();// AlertDialog dialog; create like this
// outside onClick
dialog.show();
你不知道的 'checkBox.setChecked(真);'或者我沒有正確地得到你的問題? – Darpan