StaggeredGridView
StaggeredGridView copied to clipboard
no onScrollListener support
Is there any workarounds to get the scroll position? The thing i need is to know when the list is scrolled to the bottom so I can load new data.
Here's how I tried to tackle the problem
First ,add a private instance :
private AbsListView.OnScrollListener mOnScrollListener;
Add public setOnClickListener method :
public void setOnScrollListener (AbsListView.OnScrollListener l) {
mOnScrollListener = l;
}
Then, in trackMotionScroll
, add lines of codes to invoke the listener
private boolean trackMotionScroll(int deltaY, boolean allowOverScroll) {
.
.
.
/* HERE we call onScroll */
if (mOnScrollListener != null) {
mOnScrollListener.onScroll(null, getFirstPosition(), getChildCount(), this.mItemCount);
}
return deltaY == 0 || movedBy != 0;
}
You can also implement your own onScrollStateChanged (AbsListView view, int scrollState)
method, but I am too lazy to do so :P
Finally you can call gridView.setOnScrollListener(listener)
to pass in a listener to StaggeredGridView
Hope it helps.
I added the support in my version https://github.com/GoMino/StaggeredGridView, I still need to merge the code with this version of the StaggeredGridView, I based mine on the original one in the support library.
Does this fix the setscroll ?
It works exactly the same as any other scroll listener:
private OnScrollListener mScrollListener = new OnScrollListener() {
@Override
public void onScrollStateChanged(ViewGroup view, int scrollState) {
Log.d(TAG, "[onScrollStateChanged] scrollState:" + scrollState);
switch (scrollState) {
case SCROLL_STATE_IDLE:
break;
case SCROLL_STATE_FLING:
break;
case SCROLL_STATE_TOUCH_SCROLL:
break;
default:
break;
}
}
@Override
public void onScroll(ViewGroup view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Log.d(TAG, "[onScroll] firstVisibleItem:" + firstVisibleItem + " visibleItemCount:"+visibleItemCount + " totalItemCount:" + totalItemCount);
}
};
then you set the listener via youStaggeredGridView.setOnScrollListener(mScrollListener), and you will get notified!
What I mean is does the setScrollY or scrollTo function work, course if i try i use it i just get weird results.
I remember getting a similar issue when I used that version of the StaggeredGridView, that is why I decided to rebase my work on the original one from the support library which doesn't have the problem, I would suggest you to try it out and let me know if you got any problem with it
where do i find the original and what is the downsides with using that one? Edit: Didn't read properly will try your library!
I can get how many pixels I moved?