ListView with Section Header in Android

In this post I am going to discuss “How we can create ListView with Section Header in Android?” So I am going to explain to how we create like below listview image.

put section header in android listview

 

  • First we need to create two custom layout for the list header and list row.
  • Create the object model class for Arraylist.
  • Then create custom adapter for ListView.
  • Instantiate ListView with sample data in Activity class.

Layouts for List Header and List Row

row_item.xml

header_item.xml

activity_main.xml

Object model class for Arraylist

Custom adapter for ListView

You have to override getViewTypeCount() method. This method returns the number of types of Views that will be created by getView method.

Instantiate ListView with sample data

If you follow the all the steps, now your project is ready to execute. when you run this, you will get below output on your device.

Android ListView Header Section

LearnLinky Happy Reading

Hope this article help you to understand ListView with Section Header. don’t forget to put your comments or suggestions.

One Response

  1. David June 10, 2017

Add Comment