public void setData(List<Person> people) { mItems = new ArrayList<>(); // Insert headers into list of items. String lastHeader = ""; int sectionManager = -1; int headerCount = 0; int sectionFirstPosition = 0; for (int i = 0; i < people.size(); i++) { Person p = people.get(i); String header; if (p.isFavorite()) { header = "*"; } else { header = people.get(i).getName().substring(0, 1); } if (!TextUtils.equals(lastHeader, header)) { // Insert new header view and update section data. sectionManager = (sectionManager + 1) % 2; sectionFirstPosition = i + headerCount; lastHeader = header; headerCount += 1; mItems.add(new LineItem(header, true, sectionFirstPosition)); } mItems.add(new LineItem(people.get(i), false, sectionFirstPosition)); } setMarginsFixed(true); notifyDataSetChanged(); }
public static void putFavorites(Collection<Person> list, Context context) { StringBuilder sBuilder = new StringBuilder(); for (Person p : list) { sBuilder.append(p.getEmpId()); sBuilder.append("-"); } putString(context, "favorites", sBuilder.toString()); }