When I log out the sectionList there are 20 items; for some reason, all but the last item is being entered into the section Array. Can someone see whats wrong here?
UPDATE: I posted the entire class in question; it's relatively short. It is from an Android app.
public class ItemAdapter extends ArrayAdapter<ItemObject> implements
SectionIndexer {
private HashMap<String, Integer> alphaIndexer;
private String[] sections;
private LayoutInflater inflater;
public ItemAdapter(Context context, ItemObject[] objects) {
super(context, R.layout.item_row_layout, objects);
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
alphaIndexer = new HashMap<String, Integer>();
int size = objects.length;
for (int i = 0; i < size; i++) {
ItemObject it = objects[i];
String name = it.name;
String s = name.substring(0, 1);
s = s.toUpperCase();
if (!alphaIndexer.containsKey(s)) {
alphaIndexer.put(s, i);
}
}
Set<String> sectionLetters = alphaIndexer.keySet();
ArrayList<String> sectionList = new ArrayList<String>(sectionLetters);
Collections.sort(sectionList);
sections = new String[sectionList.size()];
sections = sectionList.toArray(new String[sectionList.size()]);
}
ArrayList.toArray. Also, if you want ordered keys, use aTreeMap.