ListView with sectioned Header scrolling sticky in Android

Sectioned headers in a list are great when you want to display categorized items eg. by time/day, by product category or sales price,...

In this example, we will be using StickyListHeader library to display journal entries by day.

1. Download and import Library

- Download library project from Github.
- Launch Eclipse and start a new Android Project.
- Extract downloaded zip file, you can see "library" folder in Sticky-Listview-master folder.
- Import library project from "library" folder and make reference from current project to it:

2. Making project layouts

- Layout for activity (activity_main.xml) - only a listview in it:
- Item listview row layout (listview_row.xml):
- Layout for sectioned header (listview_header.xml):

3. Programmatically coding 

First, build a customize ListView adapter extends BaseAdapter and implements StickyListHeadersAdapter. In this, set view for each listview rows and headers from getView() and getHeaderView() methods.
Source code:

Secondly, in MainActivity, we read a list a friend's name in a text file (in assets folder), save in string List and populate them in to ListView Adapter.
- Read file from assets resource method:
- Full MainActivity.java source code:
- Running program:

4. References:

- Official library Github page: https://github.com/emilsjolander/StickyListHeaders
- Author Home page: http://emilsjolander.se/

(Sorry for having ads)

Share


Previous post
« Prev Post
Next post
Next Post »