@@ -76,6 +76,13 @@ public class ListDialogDecorator extends AbstractDialogDecorator<ButtonBarDialog
7676 */
7777 private static final String ITEMS_EXTRA = ListDialogDecorator .class .getSimpleName () + "::items" ;
7878
79+ /**
80+ * The name of the extra, which is used to store the resource ids of the iconds of the dialog's
81+ * items within a bundle.
82+ */
83+ private static final String ICON_RESOURCE_IDS_EXTRA =
84+ ListDialogDecorator .class .getSimpleName () + "::iconResourceIds" ;
85+
7986 /**
8087 * The name of the extra, which is used to store the dialog's single choice items within a
8188 * bundle.
@@ -170,6 +177,11 @@ public class ListDialogDecorator extends AbstractDialogDecorator<ButtonBarDialog
170177 */
171178 private CharSequence [] items ;
172179
180+ /**
181+ * The resource ids of the icons of the dialog's items.
182+ */
183+ private int [] iconResourceIds ;
184+
173185 /**
174186 * The dialog's single choice items.
175187 */
@@ -468,6 +480,7 @@ public final void setItems(@Nullable final CharSequence[] items,
468480 @ Nullable final int [] iconResourceIds ,
469481 @ Nullable final DialogInterface .OnClickListener listener ) {
470482 this .items = items ;
483+ this .iconResourceIds = iconResourceIds ;
471484 this .singleChoiceItems = null ;
472485 this .multiChoiceItems = null ;
473486 this .adapter = items != null ? new RecyclerViewAdapterWrapper <>(getContext (),
@@ -497,6 +510,7 @@ public final <VH extends RecyclerView.ViewHolder> void setAdapter(
497510 @ Nullable final RecyclerView .LayoutManager layoutManager ,
498511 @ Nullable final DialogInterface .OnClickListener listener ) {
499512 this .items = null ;
513+ this .iconResourceIds = null ;
500514 this .singleChoiceItems = null ;
501515 this .multiChoiceItems = null ;
502516 this .adapter = adapter != null ?
@@ -522,6 +536,7 @@ public final void setSingleChoiceItems(@Nullable final CharSequence[] items,
522536 final int checkedItem ,
523537 @ Nullable final DialogInterface .OnClickListener listener ) {
524538 this .items = null ;
539+ this .iconResourceIds = iconResourceIds ;
525540 this .singleChoiceItems = items ;
526541 this .multiChoiceItems = null ;
527542 this .adapter = items != null ? new RecyclerViewAdapterWrapper <>(getContext (),
@@ -559,6 +574,7 @@ public final <VH extends RecyclerView.ViewHolder> void setSingleChoiceItems(
559574 @ Nullable final RecyclerView .LayoutManager layoutManager , final int checkedItem ,
560575 @ Nullable final DialogInterface .OnClickListener listener ) {
561576 this .items = null ;
577+ this .iconResourceIds = null ;
562578 this .singleChoiceItems = null ;
563579 this .multiChoiceItems = null ;
564580 this .adapter = adapter != null ?
@@ -592,6 +608,7 @@ public final void setMultiChoiceItems(@Nullable final CharSequence[] items,
592608 Condition .INSTANCE .ensureTrue (checkedItems == null || items == null ||
593609 checkedItems .length == items .length , "Invalid number of checked items given" );
594610 this .items = null ;
611+ this .iconResourceIds = iconResourceIds ;
595612 this .singleChoiceItems = null ;
596613 this .multiChoiceItems = items ;
597614 this .adapter = items != null ? new RecyclerViewAdapterWrapper <>(getContext (),
@@ -636,6 +653,7 @@ public final <VH extends RecyclerView.ViewHolder> void setMultiChoiceItems(
636653 adapter .getItemCount () == checkedItems .length ,
637654 "Invalid number of checked items given" );
638655 this .items = null ;
656+ this .iconResourceIds = null ;
639657 this .singleChoiceItems = null ;
640658 this .multiChoiceItems = null ;
641659 this .adapter = adapter != null ?
@@ -679,6 +697,7 @@ public final void setOnItemEnabledListener(
679697 @ Override
680698 public final void onSaveInstanceState (@ NonNull final Bundle outState ) {
681699 outState .putParcelable (ITEM_COLOR_EXTRA , getItemColor ());
700+ outState .putIntArray (ICON_RESOURCE_IDS_EXTRA , iconResourceIds );
682701
683702 if (items != null ) {
684703 outState .putCharSequenceArray (ITEMS_EXTRA , items );
@@ -700,23 +719,24 @@ public final void onRestoreInstanceState(@NonNull final Bundle savedInstanceStat
700719 }
701720
702721 CharSequence [] items = savedInstanceState .getCharSequenceArray (ITEMS_EXTRA );
722+ int [] iconResourceIds = savedInstanceState .getIntArray (ICON_RESOURCE_IDS_EXTRA );
703723
704724 if (items != null ) {
705- setItems (items , null );
725+ setItems (items , iconResourceIds , null );
706726 } else {
707727 boolean [] checkedItems = savedInstanceState .getBooleanArray (CHECKED_ITEMS_EXTRA );
708728 CharSequence [] singleChoiceItems =
709729 savedInstanceState .getCharSequenceArray (SINGLE_CHOICE_ITEMS_EXTRA );
710730
711731 if (singleChoiceItems != null ) {
712732 int checkedItem = checkedItems != null ? indexOfCheckedItem (checkedItems ) : -1 ;
713- setSingleChoiceItems (singleChoiceItems , checkedItem , null );
733+ setSingleChoiceItems (singleChoiceItems , iconResourceIds , checkedItem , null );
714734 } else {
715735 CharSequence [] multiChoiceItems =
716736 savedInstanceState .getCharSequenceArray (MULTI_CHOICE_ITEMS_EXTRA );
717737
718738 if (multiChoiceItems != null ) {
719- setMultiChoiceItems (multiChoiceItems , checkedItems , null );
739+ setMultiChoiceItems (multiChoiceItems , iconResourceIds , checkedItems , null );
720740 }
721741 }
722742 }
0 commit comments