I am getting data from server in a listview
using a custom adapter
. The data coming from server is a large amount having images with text. Now I need to load the data each time only 10 items and when I scroll down it should load more 10 items and so on. Her is how I am setting adapter code. I don't understand now how to handle this situation inside the onscroll method. I am loading all items from server at once and assigning to an arraylist. So inside onscroll method what should I do, please help me with some code.
list = (ArrayList<ListItems>) control.Table.GetData();
final ListView listview = (ListView)findViewById(R.id.user_data);
adapter = new customAdapter(this, list);
adapter.setLayout(this, layout);
listview.setAdapter(adapter);
listview.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
final int lastItem = firstVisibleItem + visibleItemCount;
if(lastItem == totalItemCount) {
//Here I have to add next 10 items from arraylist
}
}
});
I think large amount of text and images in a listview will be handle by android, I remember in a video Google I/O that even a million rows in a listview, android can handle hit. just implement the best practice on how to manage views/rows in a listview just to avoid recreating the rows everytime it will be viewed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.