当我注销 sectionList 时,有 20 个项目;出于某种原因,除了最后一项之外的所有内容都被输入到 Array 部分。有人可以看到这里有什么问题吗?
更新:我发布了有问题的整个班级;它相对较短。它来自一个安卓应用程序。
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()]);
}