Is there a working example out there that demonstrates how to append additional rows in ListView dynamically?
For example:
- you are pulling RSS feeds from
different domains - you then display the first 10 items
in the ListView (while you have
other threads running in the
background continue pulling feeds) - you scroll and reach the bottom of
the List and click at a button to
view more items - the ListView will then get appended
with additional 10 items, which
makes 20 items now in total.
Any advice how to accomplish this?
Nicholas
To add new item to your list dynamically you have to get adapter class from your ListActivity and simply add new elements. When you add items directly to adapter, notifyDataSetChanged is called automatically for you – and the view updates itself.
You can also provide your own adapter (extending ArrayAdapter) and override the constructor taking List parameter. You can use this list just as you use adapter, but in this case you have to call adapter.notifyDataSetChanged() by yourself – to refresh the view.
Please, take a look at the example below:
}
You can extend the example above and add “more” button – which just add new items to your adapter (or vector).
Regards!