user1708001
user1708001

Reputation: 63

How to simply add header in a Listview ?

I made a listView, now is there a simple way to add hearders in it ? For example, make something like this

List.add("a")
list.addheader("Number")
list.add("1")
.
.
Widget_List_Adapter adapter = new Widget_List_Adapter(this, list);
.
.
.
setListAdapter(adapter);

Upvotes: 0

Views: 3595

Answers (4)

Adeel Pervaiz
Adeel Pervaiz

Reputation: 1356

There's no section List(Table) View in Android, you can just add one top header, but if you want to make something like sectioned table view like IOS, here are some better resources.

android-section-list Just use this library it is awesome.

android-amazing-listview This one is also very user, even it allows you to load more functionality like FB.

How ever you can also make your own custom list, here is the complete blog.

Upvotes: 0

BigBen3216
BigBen3216

Reputation: 867

you could define a layout with a header layout followed by the listview. in the header layout you can define a textview that you can change in your code

Upvotes: 1

Khantahr
Khantahr

Reputation: 8528

The addHeaderView() option only works to add a static header at the top of your list. If you want to add section headers, you'll have to do a considerable amount of extra work. This question should lead you down the proper path to make that happen.

Upvotes: 0

Sam
Sam

Reputation: 86948

Try using ListView#addHeaderView().

As a warning, you must call this method before calling setAdapter() or setListAdapter(), just like your pseudo-code example.

Upvotes: 6

Related Questions