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();
}
}