Reputation: 3617
The purpose of the app is to fetch more data as the user scrolls down and updates existing ListView.
Code snippet handling user scroll is:
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
int totalVisible = firstVisibleItem + visibleItemCount;
if (view.getAdapter() != null &&
(totalVisible >= totalItemCount) &&
totalItemCount != priorFirst &&
visibleItemCount != totalItemCount) {
Log.v("MyActivity", "onListEnd, extending list");
priorFirst = totalItemCount;
//params is array of values passed to business layer for data fetch
String[] params = builder.toString().split("&");
UIHandler uiHandler = new UIHandler(this, getParent());
//start async task
EnquiriesRunner enquiriesRunner = new EnquiriesRunner(uiHandler);
enquiriesRunner.execute(params);
}
In the background, it invokes business layer.
protected ExceptionHandler<Object> doInBackground(String... params) {
Object obj = enquiriesCaller.getEnquiries(params);
return new ExceptionHandler<Object>(obj);
}
And pass the resulting data to UI handler which renders it to a listView using a custom adapter.
ListView enquiryView = (ListView) ((Activity) childContext).findViewById(R.id.enquiryListView);
CustomAdapter adapter = new CustomAdapter(childContext, msg.obj);
enquiryView.setAdapter(adapter);
msg.obj is the search result wrapped into an Object. This will be casted to required POJO reference in the adapter.
As you can see, each time listView is replaced with new set of data. Could anyone suggest a possible solution to update existing List?
Thanks in advance!
Upvotes: 0
Views: 4628
Reputation: 2311
Try this link it will be useful for you.
http://benjii.me/2010/08/endless-scrolling-listview-in-android/
you can update ListView on Scrolling..
Upvotes: 1