How To Detect Android Listview Scrolling Stopped?
I'm trying to do something after scrolling stopped.So, I tried using OnScrollListener#onScrollStateChanged(SCROLL_STATE_IDLE) to detect when the scrolling stopped(either TOUCH_SCRO
Solution 1:
Try using the setOnScrollListener and implement the onScrollStateChanged with scrollState == 0 ... do what you need to do...
setOnScrollListener(new OnScrollListener() {
publicvoidonScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
}
publicvoidonScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
Log.i("a", "scrolling stopped...");
}
}
});
Solution 2:
The trick is to keep track of when the user is flinging and when they are not. It seems like this is about the only distinction you can make because, like you said, the transitions from scrolling with a finger to idle are not recorded. Here's what I'm talking about:
publicvoidonScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState != OnScrollListener.SCROLL_STATE_FLING) {
flinging = false;
intcount= view.getChildCount();
for (inti=0; i < count; i++) {
ViewconvertView= view.getChildAt(i);
Reciperecipe= (Recipe) convertView.getTag();
ImageViewimage= (ImageView) convertView.findViewById(R.id.icon);
if (recipe != null && recipe.getImageURL() != null) {
ImageLoader.loadImage(this, image, recipe.getImageURL());
}
}
} else {
flinging = true;
}
}
And then in the listView adapter:
public View getView(int position, View convertView, ViewGroup parent){
// Bunch of code....if (!flinging) {
ImageLoader.loadImage(BrowseRecipes.this, image, recipe.getImageURL());
}
}
So, instead of reacting to the change in the listener, just load the images (or whatever you need to do that's intensive) in the first place as long as there's no flinging going on.
This is all taken out of my project here: https://github.com/pkulak/mealfire_android
Post a Comment for "How To Detect Android Listview Scrolling Stopped?"