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.
2. Making project layouts
- Layout for activity (activity_main.xml) - only a listview in it:
- 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