Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android listview groups

I have Activity for displaying search results. It extends ListActivity. I need to show search results in listview grouping several items. So, how do I add grouping to my listview?


1 Answers

You give your ListView a ListAdapter that knows how to do the grouping.

This could be a matter of overriding getViewTypeCount() and getItemViewType() in the adapter to describe which positions get which sorts of rows, plus modifying getView() (or newView() and bindView() for CursorAdapter) as needed.

Depending on what you are starting with, you might be able to use something like my MergeAdapter instead.

like image 176
CommonsWare Avatar answered Jul 19 '26 00:07

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!