Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: ListView, Last item - Show more

I have an issues, I want to show 20 items in the list. But there is a catch: if the user scrolls down to the bottom of the list, there will be an item that says: "Show more items", and when the users click on it, more items will be added to the list.

My question is how is poosible to have a last item, that has a different style and looks different: and does different things,(I think this is used in QuickSearchbox)

like image 777
Troj Avatar asked Jun 21 '10 14:06

Troj


3 Answers

If you still want a clickable item rather than an infinitely scrolling list you can try using ListView#addFooterView to add your "Show more items" item. This lets you add a view as the last item in a list. Make sure you call it before calling setAdapter.

like image 196
adamp Avatar answered Oct 04 '22 00:10

adamp


I would recommend you commonsware's cwac-endless.

cwac-endless: Provides the EndlessAdapter, a wrapper for an existing ListAdapter that adds "endless list" capability. When the user scrolls to the bottom of the list, if there is more data for this list to be retrieved, your code gets invoked in a background thread to fetch the new rows, which then get seamlessly attached to the bottom of the list.

like image 29
Macarse Avatar answered Oct 04 '22 00:10

Macarse


While commonware has some awesome stuff. His endless lib may not be what you want. What you probably want is a footer. On your ListView, before you set your adapter, call addFooterView. Note that if you do that, the adapter you get from ListView.getAdapter will not be the same as what you passed to ListView.setAdapter.

Edit Speaking of commonware, he sells a few books on his site. Buy them. They are the best $40 you will spend on your android education.

like image 24
Jere.Jones Avatar answered Oct 04 '22 00:10

Jere.Jones