views:

121

answers:

4

Hi!

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)

+1  A: 

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.

Macarse
Thanks a lot for the answer, do you have any sample, or any pages that can help me out,
Troj
WTF? Macarse already gave you the link to the example: http://github.com/commonsguy/cwac-endless what else could you need?
Cristian
A: 

In the layout below the listview you can put a linear layout with "Clear" and "Get More Results" buttons. Not exactly what you are asking but it can achieve the same result.

BrennaSoft
A: 

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.

Jere.Jones
thanks, so you suggest that I should use a footer,, do you have any example on this as well?
Troj
Sure. They talk about it and show an example in the Google I/O 2010 talk on ListView: http://code.google.com/events/io/2010/sessions/world-of-listview-android.html
Jere.Jones
If you don't want to watch the video (although you should), the example is in the PDF.
Jere.Jones
A: 

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 only call it after calling setAdapter.

adamp
thanks a lot, do you know how I can add to the footer a clicklistner.
Troj
addFooterView takes a View. just set the onClickListener on that view.
Jere.Jones