Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PullDown Android detector
import android.widget.AbsListView;
import android.widget.ListView;
/**
* Makes a listview to have a pull down, this is a wrapper.
* Is not a good idea to override a ListView because there
* are a lot of libraries and we dont know when we need one.
*/
public class PulldownListViewHelper {
private final static int ITEMS_BEFORE_LAST_TO_DETECT = 3;
private ListView listView;
private OnPullDownListener listener;
AbsListView.OnScrollListener scrolllistener = new AbsListView.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 (listener != null && lastItem >= (totalItemCount - ITEMS_BEFORE_LAST_TO_DETECT)) {
listener.onPullDown();
}
}
};
public PulldownListViewHelper(ListView listView, OnPullDownListener listener) {
this.listView = listView;
this.listener = listener;
}
public void initPulldown() {
listView.setOnScrollListener(scrolllistener);
}
public void stopPulldown() {
listView.setOnScrollListener(null);
}
public interface OnPullDownListener {
void onPullDown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.