android - setItemChecked is not working
<p>I am trying to make one checkbox checked if the dialog is opened, but setItemChecked doesn't seem to be working.. Here is my code. I already checked other answers, but it doesn't help. Does anybody know if there is something wrong with my code?</p>

<p>Thanks.</p>

<pre><code>        alertDialogBuilder.setMultiChoiceItems(R.array.list_array, list_values, new DialogInterface.OnMultiChoiceClickListener() {
        public void onClick(DialogInterface dialog, int item, boolean isChecked) {
            Toast.makeText(getContext(), "You have selected " + list[item], Toast.LENGTH_SHORT).show();
        }
    });
    alertDialogBuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            SparseBooleanArray checkedItems = ((AlertDialog) dialog).getListView().getCheckedItemPositions();
            int size = checkedItems.size();
            Toast.makeText(getContext(), "Save " + size, Toast.LENGTH_SHORT).show();
        }
    });
    alertDialog = alertDialogBuilder.create();
    if (isAlreadyOpened) {
        alertDialog.getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        alertDialog.getListView().setItemChecked(4, true);
    }
</code></pre>
