public ListAdapter(Context context) { this.inflater = LayoutInflater.from(context); alphaIndexer = new HashMap<String, Integer>(); sections = new String[ShowCity_lists.size()]; for (int i = 0; i < ShowCity_lists.size(); i++) { // 当前汉语拼音首字母 String currentStr = getAlpha(ShowCity_lists.get(i).getPinyi()); // 上一个汉语拼音首字母,如果不存在为“ ” String previewStr = (i - 1) >= 0 ? getAlpha(ShowCity_lists.get(i - 1).getPinyi()) : " "; if (!previewStr.equals(currentStr)) { String name = getAlpha(ShowCity_lists.get(i).getPinyi()); alphaIndexer.put(name, i); sections[i] = name; } } }
@Override public int getCount() { return ShowCity_lists.size(); }