0

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);
user1708001
  • 63
  • 2
  • 5

4 Answers4

6

Try using ListView#addHeaderView().

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

Sam
  • 86,580
  • 20
  • 181
  • 179
1

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

BigBen3216
  • 868
  • 1
  • 8
  • 23
0

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.

Community
  • 1
  • 1
Khantahr
  • 8,156
  • 4
  • 37
  • 60
0

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.

Adeel Pervaiz
  • 1,336
  • 10
  • 11