I’ve implemented a ListView for reading an rss feed and I would like to implement an autoscroll for this list view.
I’ve probably to use something like:
listView.post(new Runnable() {
@Override
public void run() {
listView.smoothScrollToPosition(???);
}
});
but how to read smoothly all the position and then start from the top again?
Well, you could simply iterate through the elements in the list view by using some sort of counter:
Instead of using
post(), you may want to think about using aTimerobject instead, as I believe there isn’t much control about when runnable’s on the post queue are executed.EDIT
So I managed to get a rudimentary, but working, example by using a
Timerwith a fixed-rate scheduledScrollTimerTaskThen, where you want to start moving down the list call
new Timer().scheduleAtFixedRate(new ScrollTimerTask(), 0, 1000);. This will start scrolling after no delay, and will schedule the scrolling task every 1000ms.Note this is rudimentary and will crash the Activity when you close it, and runs continuously. To prevent the crash, I’d recommend keeping a reference to the
Timerobject and callingTimer.cancel()in the Activity’s onPause() method. But it is a starting block!