code: @NonNull
      private ListDialog.OnItemSelectedListener createItemSelectedListener() {
          return new ListDialog.OnItemSelectedListener() {
  
              @Override
              public void onItemSelected(final int position) {
                  ColorPalettePreference.this.selectedIndex = position;
                  ColorPalettePreference.this.onClick(getDialog(), DialogInterface.BUTTON_POSITIVE);
  
                  if (getDialog() != null) {
                      getDialog().dismiss();
                  }
              }
  
          };
      }
docs: Creates and returns a listener, which allows to observe when a list item has been selected.
  
  @return The listener, which has been created, as an instance of the type {@link
  ListDialog.OnItemSelectedListener}. The listener may not be null