SectionAdapter

Here's what you get with Section adapter:

  • Pinned headers
  • An easy method of putting your data into sectioned data without the hassle of writing routines to find the position in section, etc.
  • Easily swap out assets depending on whether you're in first of section, end of section, etc. (note the rounded corner backgrounds for the listview items)
  • ListView searching (optional)
  • Support for "fastscroll" if specified in listviewSection adapter
  • The model that you are populating the listview with must implement Sectionable.java
    public class Person implements Sectionable {
    
        private String name;
    
        private String city;
    
        public Person(String name, String city) {
            this.name = name;
            this.city = city;
        }
    
        public String getName() {
            return name;
        }
    
        public String getCity() {
            return city;
        }
    
        //
        @Override
        public String getSection() {
            return city;
        }
    
        /*
         * when filtering occurs, it is doing a case-insensitive search on toString()
         * for more complex matching, implement Queryable on your model
         *
         */
        @Override
        public String toString() {
            return name + " " + city;
        }
    
    
    }
    
  • Simply pass a List of your Sectionable object model to the adapter..
            List<Person> persons = new ArrayList<Person>();
    
            persons.add(new Person("Kermit the Frog", "Chicago"));
            persons.add(new Person("Miss Piggy", "Chicago"));
            persons.add(new Person("Miss Piggy", "Chicago"));
            persons.add(new Person("Miss Piggy", "Chicago"));
            persons.add(new Person("Miss Piggy", "Chicago"));
            persons.add(new Person("Miss Piggy", "Chicago"));
            persons.add(new Person("Miss Piggy", "Chicago"));
            persons.add(new Person("Gonzo", "Chicago"));
    
            persons.add(new Person("Mister Rogers", "Pittsburgh"));
    
            persons.add(new Person("Leonardo", "New York"));
            persons.add(new Person("Michelangelo", "New York"));
            persons.add(new Person("Michelangelo", "New York"));
            persons.add(new Person("Donatello", "New York"));
            persons.add(new Person("Raphael", "New York"));
            persons.add(new Person("Michelangelo", "New York"));
            persons.add(new Person("Donatello", "New York"));
            persons.add(new Person("Raphael", "New York"));
            persons.add(new Person("Michelangelo", "New York"));
            persons.add(new Person("Donatello", "New York"));
            persons.add(new Person("Raphael", "New York"));
            persons.add(new Person("Michelangelo", "New York"));
            persons.add(new Person("Donatello", "New York"));
            persons.add(new Person("Raphael", "New York"));
            persons.add(new Person("Donatello", "New York"));
            persons.add(new Person("Raphael", "New York"));
    
            persons.add(new Person("Captain Crunch", "Orlando"));
            persons.add(new Person("Soggies", "Orlando"));
    
            persons.add(new Person("Pooh Bear", "Hundred Acre Wood"));
            persons.add(new Person("Eor", "Hundred Acre Wood"));
            persons.add(new Person("Owl", "Hundred Acre Wood"));
            persons.add(new Person("Tigger", "Hundred Acre Wood"));
            persons.add(new Person("Piglet", "Hundred Acre Wood"));
            persons.add(new Person("Owl", "Hundred Acre Wood"));
            persons.add(new Person("Tigger", "Hundred Acre Wood"));
            persons.add(new Person("Piglet", "Hundred Acre Wood"));
            persons.add(new Person("Owl", "Hundred Acre Wood"));
            persons.add(new Person("Tigger", "Hundred Acre Wood"));
            persons.add(new Person("Piglet", "Hundred Acre Wood"));
            persons.add(new Person("Owl", "Hundred Acre Wood"));
            persons.add(new Person("Tigger", "Hundred Acre Wood"));
            persons.add(new Person("Piglet", "Hundred Acre Wood"));
    
            adapter.setData(persons);
            adapter.notifyDataSetChanged();