title: Android Custom ListPreference only allow 5 items
body: <p>Im creating a custom ListPreference on the back of <a href="http://www.lucazanini.eu/2014/android/display-icon-preferences/#comment-29209" rel="nofollow">this</a> example. </p>
  
  <p>I've implemented it and it works. But I can only add a max of 5 item to the ListPreference. If I add 7 items they appears in the list but when I click it it does nothing, just closes the ListPref dialog and return to the pref screen</p>
  
  <pre><code>public class IconPickerPreference extends ListPreference {
  
  private class CustomListPreferenceAdapter extends ArrayAdapter&lt;IconItem&gt; {
  
      private Context context;
      private List&lt;IconItem&gt; icons;
      private int resource;
  
      public CustomListPreferenceAdapter(Context context, int resource, List&lt;IconItem&gt; objects) {
          super(context, resource, objects);
          this.context = context;
          this.resource = resource;
          this.icons = objects;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
  
          ViewHolder holder;
  
          if (convertView == null) {
              LayoutInflater inflater = (LayoutInflater) context
                      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = inflater.inflate(resource, parent, false);
  
              holder = new ViewHolder();
              holder.iconName = (TextView) convertView
                      .findViewById(R.id.iconName);
              holder.iconImage = (ImageView) convertView
                      .findViewById(R.id.iconImage);
              holder.radioButton = (RadioButton) convertView
                      .findViewById(R.id.iconRadio);
              holder.position = position;
  
              convertView.setTag(holder);
          } else {
              holder = (ViewHolder) convertView.getTag();
          }
  
          holder.iconName.setText(icons.get(position).name);
  
          int identifier = context.getResources().getIdentifier(
                  icons.get(position).file, "drawable",
                  context.getPackageName());
          holder.iconImage.setImageResource(identifier);
  
          holder.radioButton.setChecked(icons.get(position).isChecked);
  
          convertView.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  ViewHolder holder = (ViewHolder) v.getTag();
                  for (int i = 0; i &lt; icons.size(); i++) {
                      if (i == holder.position)
                          icons.get(i).isChecked = true;
                      else
                          icons.get(i).isChecked = false;
                  }
                  getDialog().dismiss();
              }
          });
  
          return convertView;
      }
  
  }
  
  private static class IconItem {
  
      private String file;
      private boolean isChecked;
      private String name;
  
      public IconItem(CharSequence name, CharSequence file, boolean isChecked) {
          this(name.toString(), file.toString(), isChecked);
      }
  
      public IconItem(String name, String file, boolean isChecked) {
          this.name = name;
          this.file = file;
          this.isChecked = isChecked;
      }
  
  }
  
  private static class ViewHolder {
      protected ImageView iconImage;
      protected TextView iconName;
      protected int position;
      protected RadioButton radioButton;
  }
  
  private Context context;
  private ImageView icon;
  
  private CharSequence[] iconFile;
  private CharSequence[] iconName;
  private List&lt;IconItem&gt; icons;
  private SharedPreferences preferences;
  private Resources resources;
  private String selectedIconFile, defaultIconFile;
  private TextView summary;
  
  public IconPickerPreference(Context context, AttributeSet attrs) {
      super(context, attrs);
      this.context = context;
  
      resources = context.getResources();
      preferences = PreferenceManager.getDefaultSharedPreferences(context);
  
      TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
              R.styleable.attrs_icon, 0, 0);
  
      try {
          defaultIconFile = a.getString(R.styleable.attrs_icon_iconFile);
      } finally {
          a.recycle();
      }
  }
  
  private String getEntry(String value) {
      String[] entries = resources.getStringArray(R.array.iconName);
      String[] values = resources.getStringArray(R.array.iconFile);
      int index = Arrays.asList(values).indexOf(value);
      return entries[index];
  }
  
  @Override
  protected void onBindView(View view) {
      super.onBindView(view);
  
      selectedIconFile = preferences.getString(
              resources.getString(R.string.custom_icon_key), defaultIconFile);
  
      icon = (ImageView) view.findViewById(R.id.iconSelected);
      updateIcon();
  
      summary = (TextView) view.findViewById(R.id.summary);
      summary.setText(getEntry(selectedIconFile));
  
  }
  
  @Override
  protected void onDialogClosed(boolean positiveResult) {
      super.onDialogClosed(positiveResult);
  
      if (icons != null) {
          for (int i = 0; i &lt; icons.size(); i++) {
              IconItem item = icons.get(i);
              if (item.isChecked) {
  
                  Editor editor = preferences.edit();
                  editor.putString(
                          resources.getString(R.string.custom_icon_key),
                          item.file);
                  editor.apply();
  
                  selectedIconFile = item.file;
                  updateIcon();
  
                  summary.setText(item.name);
  
                  break;
              }
          }
      }
  
  }
  
  @Override
  protected void onPrepareDialogBuilder(Builder builder) {
  
      builder.setNegativeButton("Cancel", null);
      builder.setPositiveButton(null, null);
  
      iconName = getEntries();
      iconFile = getEntryValues();
  
      if (iconName == null || iconFile == null
              || iconName.length != iconFile.length) {
          throw new IllegalStateException(
                  "ListPreference requires an entries array "
                          + "and an entryValues array which are both the same length");
      }
  
      String selectedIcon = preferences.getString(
              resources.getString(R.string.custom_icon_key),
              resources.getString(R.string.icon_default));
  
      icons = new ArrayList&lt;IconItem&gt;();
  
      for (int i = 0; i &lt; iconName.length; i++) {
          boolean isSelected = selectedIcon.equals(iconFile[i]) ? true
                  : false;
          IconItem item = new IconItem(iconName[i], iconFile[i], isSelected);
          icons.add(item);
      }
  
      CustomListPreferenceAdapter customListPreferenceAdapter = new CustomListPreferenceAdapter(
              context, R.layout.item_picker, icons);
      builder.setAdapter(customListPreferenceAdapter, null);
  
  }
  
  private void updateIcon() {
      int identifier = resources.getIdentifier(selectedIconFile, "drawable",
              context.getPackageName());
  
      icon.setImageResource(identifier);
      icon.setTag(selectedIconFile);
  }
  </code></pre>
  
  <p>String values</p>
  
  <pre><code> &lt;string-array name="iconName"&gt;
      &lt;item&gt;CHESTNUT&lt;/item&gt;
      &lt;item&gt;POMEGRANATE&lt;/item&gt;
      &lt;item&gt;OLD BRICK&lt;/item&gt;
      &lt;item&gt;FLAMINGO&lt;/item&gt;
      &lt;item&gt;SNUFF&lt;/item&gt;
      &lt;item&gt;RAZZMATAZZ&lt;/item&gt;
      &lt;item&gt;NEW YORK PINK&lt;/item&gt;
  &lt;/string-array&gt;
  
  &lt;string-array name="iconFile"&gt;
      &lt;item&gt;ic_chestnut&lt;/item&gt;
      &lt;item&gt;ic_pomegranate&lt;/item&gt;
      &lt;item&gt;ic_old_brick&lt;/item&gt;
      &lt;item&gt;ic_flamingo&lt;/item&gt;
      &lt;item&gt;ic_snuff&lt;/item&gt;
      &lt;item&gt;ic_razzmatazz&lt;/item&gt;
      &lt;item&gt;ic_new_york_pink&lt;/item&gt;
  &lt;/string-array&gt;
  </code></pre>
  
  <p>7 ic_ pngs for the items above in drawable...</p>
  
  <p>Logs not showing any index error...</p>
  
  <p>Stumped :P</p>
  
  <p>Any help appreciated</p>
  
  <p>Thanks in advance </p>