I searched for this, and tried many things, and for sometime it seemed solved, but it wasn’t
This is my application behaviour:
1. ListView with 1st 10 items fetched from a web server in an AsyncTask, and stored in an ArrayList.
2. Set this ArrayList to the Adapter
3. onScroll, if reached last item, fetch 10 more items, add to the ArrayList and so on
Problem:
There is a button on every item to thank , which has an initial count took from the data of that particular item, from the ArrayList.
let it be 10
Since this is an action item, i had a onClickListener for this button in the getView() in the Adapter.
onClick(){
//change the count to count+1 or change 10 to 11
}
this works but when i scroll the List, this count is set back to count (10) instead of retaining count + 1 (11). This is because the item is being recreated, and the data being used to get count is from the ArrayList, which is old 1 (10). To make this work i need to update the data in the server, get it back and store in the ArrayList and use it to get count + 1 (11).
Is there a way to do this. Because i cant call the server to give me new data every time an action item is clicked. Because this will be something like ListView is recreated, losing all the scrolled items.
Thank You
If by focused you mean selected (scrolled down by the keyboard, has the selection rectangle around it) then just use
setOnItemSelectedListener. The int argument is the position, compare that to the number of items in your list and you’re golden.If by focused you mean visible, then use
setOnScrollListener, which has this method:Just first + visible will get the last item shown, which you can compare to the total. then write update the adapter with remaining items…