0

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!

Renjith
  • 3,457
  • 5
  • 46
  • 67
  • Possible duplicate of http://stackoverflow.com/questions/2332847/how-to-create-a-closed-circular-listview – Lalith B Jan 03 '13 at 12:25

1 Answers1

1

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..

Pankaj Singh
  • 2,241
  • 2
  • 16
  • 16
  • Thanks for the link! Well, as you can see the scrolling works perfect and calls for server. The hurdle is to update the same existing list so that the user can see all values from row 0 – Renjith Jan 03 '13 at 12:41
  • use this mAdapter.notifyDataSetChanged(); where mAdapter is your Adapter Object which you used to populate data in ListView. – Pankaj Singh Jan 03 '13 at 12:43
  • Sorry to say that it failed too..! However, I managed to get it done by checking total number of rows. – Renjith Jan 03 '13 at 17:31