/** * 为list添加数据 * * @param userEntity * @return */ private void addData(UserEntity userEntity) { ContactsItemData data = new ContactsItemData(); // 添加用户名 data.setContactsUserName(userEntity.getUsername()); // 添加昵称 data.setContactsUserNickname(userEntity.getUserNickName()); // 添加头像的网络地址 data.setContactsUserHeadImageURL(userEntity.getUserHeadImageUrl()); // 汉字转拼音 String pinyin = mCharacterParser.getSelling(userEntity.getUserNickName()); String sortString = pinyin.substring(0, 1).toUpperCase(); // 正则表达式,判断首字母是否为英文字母 if (sortString.matches("[A-Z]")) { data.setSortLetters(sortString); } else { data.setSortLetters("#"); } mContactsList.add(data); }
private void filterData(String filterData) { List<ContactsItemData> filterDataList = new ArrayList<ContactsItemData>(); if (TextUtils.isEmpty(filterData)) { filterDataList = mContactsList; } else { filterDataList.clear(); for (ContactsItemData item : mContactsList) { String name = item.getContactsUserNickname(); if (name.indexOf(filterData) != -1 || mCharacterParser.getSelling(name).startsWith(filterData.toString())) { filterDataList.add(item); } } } // 根据a-z排序 Collections.sort(filterDataList, mPinyinComparator); mContactsListViewAdapter.updateListView(filterDataList); }
/** * 为list添加数据 * * @param data * @return */ private List<ContactsItemData> addData(String[] data) { List<ContactsItemData> itemData = new ArrayList<>(); for (int i = 0; i < data.length; i++) { ContactsItemData model = new ContactsItemData(); model.setContactsUserNickname(data[i]); // 汉字转拼音 String pinyin = mCharacterParser.getSelling(data[i]); String sortString = pinyin.substring(0, 1).toUpperCase(); // 正则表达式,判断首字母是否为英文字母 if (sortString.matches("[A-Z]")) { model.setSortLetters(sortString); } else { model.setSortLetters("#"); } itemData.add(model); } return itemData; }