protected override void OnPrepareDialogBuilder(AlertDialog.Builder builder) { base.OnPrepareDialogBuilder(builder); var preference = GetPreference(); if (preference.GetEntries() == null || preference.GetEntryValues() == null) { throw new Java.Lang.IllegalStateException( "MultiSelectListPreference requires an entries array and an entryValues array."); } var checkedItems = preference.GetSelectedItems(); var values = preference.GetEntryValues(); var entries = preference.GetEntries(); builder.SetMultiChoiceItems(entries, checkedItems, (s, e) => { if (_readOnlyEntriesPosition?.Count > 0 && _listView != null && _readOnlyEntriesPosition.Contains(e.Which)) { _listView.SetItemChecked(e.Which, !e.IsChecked); return; } _preferenceChanged = true; if (e.IsChecked) { _newValues.Add(values[e.Which]); } else { _newValues.Remove(values[e.Which]); } }); if (preference.ReadOnlyEntries?.Count > 0) { var entriesList = preference.GetEntries().ToList(); if (entriesList.Count > 0) { var readOnlyEntries = (from entry in entriesList from readOnlyEntry in preference.ReadOnlyEntries where string.Equals(entry, readOnlyEntry, StringComparison.OrdinalIgnoreCase) select entry).ToArray(); if (readOnlyEntries.Length > 0) { _readOnlyEntriesPosition = readOnlyEntries.Select(p => entriesList.IndexOf(p)).ToArray(); } } } _newValues.Clear(); for (var i = 0; i < checkedItems.Length; i++) { if (!checkedItems[i]) { continue; } _newValues.Add(values[i]); } }