How to add section separators / dividers to a ListView?

If you want simple sections in your ListView, take a look at this tutorial:

http://cyrilmottier.com/2011/07/05/listview-tips-tricks-2-section-your-listview/

or this tutorial:

http://bartinger.at/listview-with-sectionsseparators/

The second one is not as detailed, but probably easier to understand / kept simpler.

The basic idea is that you make your ListAdapter have different kinds of views. For example two different Views where one kind is the actual list item displaying the information, and the other kind of View being the Section divider.

From the tutorial:

ListViews and more specifically Adapters can handle several types of Views. If you take a look at the Adapter interface you will notice it contains two specific methods:

  • getViewTypeCount() which returns the number of types of Views your
    AdapterView manages. Most of the time this method returns 1 because
    all items of the ListView are similar. In this case, by returning 2,
    the ListView will handle two types of Views: the regular item Views
    and the separator Views
  • getItemViewType(int) must return an integer between 0 (inclusive) and
    getViewTypeCount() (exclusive). The given number expresses the type
    of the View at the given position. For instance, we can ensure the
    returned values are 0 for the regular item Views and 1 for the
    separators

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)