Use an OnScrollListener, the onScrollStateChanged()
method is called when the ListView switches between SCROLL_STATE_IDLE
, SCROLL_STATE_TOUCH_SCROLL
(slower scrolling), and SCROLL_STATE_FLING
(faster scrolling). With this you can choose to load new images only when the states is "Idle" or "Touch".
Addition
In the first run the visible items of the ListView aren't shown. For example when the app starts if the ListView has 4 items visible those 4 images should be loaded.
I haven't used the Universal Image Loader myself, but from what you described below you need to know how many rows will be displayed before you start downloading. Try this:
- Write a Runnable to start the asynchronous downloads.
- Use your ListView's built-in Handler to call the Runnable after the rows have been drawn
For example:
private Runnable loadImages = new Runnable() {
@Override
public void run() {
// Start the asynchronous downloads
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mListView.post(loadImages);
}
The loadImages
will be called after the ListView is drawn so you will know exactly how many rows are visible.