I am wondering how could i divide my ListView
in parts and display only one part of it when user starts my app and display others when user press a Button called "Load More Items".
I have a big list of more than 500 items and thinking to divide it into parts so it could load fast.
I want functionality similar to an any email app which gives an option at the bottom to load more emails.
If anyone has any sample code for my problem then please share else a little guidance would also be appreciated.
Initially load part of data in your list view. You have to use concept of
Handler
. onclick event you have to send message to handler inside handler you have to write the logic to load your full data and callnotifydataSetChanged
methodhave a look on the sample code below. Initially user is able to see some part of list. If user cvlicks on any list item then list user is able to see the whole list view. It is similar to as that you are expecting.
Sample Code
Thanks Deepak
well implementing a button is easy enough:
in your onCreate, load your adapter with the 1st 50 items, then implement a button with an onClickListener that adds the next 50 etc.
HOWEVER I think what you really want to do is lazy load your listview so as they scroll, it will load more items - that why you don't need to clutter the UI with an extra button.
for this your listactivity should implement OnScrollListener
here is an example of that: Android Endless List
From your question, it seems that you want to load few items initially and then load more items in future whenever user click on the "Load More items" button.
For that there can be two cases possible:
First case: webservice can send response in parts, like first time it sends 20 items, and next time 20 items whenever user clicks on "Load more items" button.
Second case: If you get 500 items in response, then to implement "Load more items" kind of functionality, you have to create database table to store all the items. Once you are done with database value storing, fetch 20 items initially, next time load 20 items and so on.