/** * ΪListView������� * * @param date * @return */ private List<GodLiuSortModel> filledData(String[] date) { List<GodLiuSortModel> mSortList = new ArrayList<GodLiuSortModel>(); if (date == null) { return mSortList; } for (int i = 0; i < date.length; i++) { GodLiuSortModel godLiuSortModel = new GodLiuSortModel(); godLiuSortModel.setName(date[i]); godLiuSortModel.setChecked(false); godLiuSortModel.index = i; // 汉字转换成拼音 String pinyin = godLiuCharacterParser.getSelling(date[i]); String sortString = pinyin.substring(0, 1).toUpperCase(); // 正则表达式,判断首字母是否是英文字母 if (sortString.matches("[A-Z]")) { godLiuSortModel.setSortLetters(sortString.toUpperCase()); } else { godLiuSortModel.setSortLetters("#"); } mSortList.add(godLiuSortModel); } return mSortList; }
/** * 根据输入框中的值来过滤数据并更新ListView * * @param filterStr */ private void filterData(String filterStr) { List<GodLiuSortModel> filterDateList = new ArrayList<GodLiuSortModel>(); if (TextUtils.isEmpty(filterStr)) { filterDateList = SourceDateList; } else { filterDateList.clear(); for (GodLiuSortModel godLiuSortModel : SourceDateList) { String name = godLiuSortModel.getName(); if (name.indexOf(filterStr.toString()) != -1 || godLiuCharacterParser.getSelling(name).startsWith(filterStr.toString())) { filterDateList.add(godLiuSortModel); } } } // 根据a-z进行排序 Collections.sort(filterDateList, godLiuPinyinComparator); adapter.updateListView(filterDateList); }