0

On my activity I have a XML parser that populates a custom ListView. When I scroll down the list view I want the activity calls again the method that parse (via AsyncTask) the xml with new items (I call a web service with a url method like '&page=1', '&page=2', etc.).

All works good but when the activity updates the listview, I loose its last position and the listview returns on top.

Here's the setOnScrollListener:

my_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)
                {
                   new Connection().execute();

                }
            }
        });

And there the method to call the async task to invoke the xml parser:

public class Connection extends AsyncTask<Void, Void, ArrayList<String>> {

       @Override
        protected ArrayList<String> doInBackground(Void... voids) {
            executeUrlXML(); //xml parser
            return null;
        }
        @Override
        protected void onPostExecute(ArrayList<String> result) {    
            super.onPostExecute(result);
            my_listview.setAdapter(adapter);
            adapter.notifyDataSetChanged();
      }
    }
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
gabboSonc
  • 351
  • 2
  • 4
  • 16
  • Possible duplicate of [notifyDataSetChanged() makes the list refresh and scroll jumps back to the top](https://stackoverflow.com/questions/17695594/notifydatasetchanged-makes-the-list-refresh-and-scroll-jumps-back-to-the-top) – MJM Aug 25 '18 at 12:32
  • so... which to delete? – gabboSonc Aug 25 '18 at 12:35

0 Answers0