I tried to add Scroll listener in StaggeredGridView
there i can't figure out a way to add that there is no implementations for that i can see
Github url
https://github.com/maurycyw/StaggeredGridView
Thanks
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 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.
Create a class that inherits SwipeRefreshLayout and override canChildScrollUp() method to check if StaggeredGridView reached the top or not, if it reached the top return true else return false.
public class SwipeDownToRefrsh extends SwipeRefreshLayout{
PullToRefreshStaggeredGridView pullToRefreshStaggeredGridView;
public SwipeDownToRefrsh(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public void canChildScrollUp (PullToRefreshStaggeredGridView pullToRefreshStaggeredGridView) {
this.pullToRefreshStaggeredGridView = pullToRefreshStaggeredGridView;
}
@Override
public boolean canChildScrollUp() {
// TODO Auto-generated method stub
if (pullToRefreshStaggeredGridView == null) {
return true;
} else {
return !pullToRefreshStaggeredGridView.getRefreshableView().mGetToTop;
}
}
}
In your Activity or Fragment just send the instant of your StaggeredGridView like this :
((SwipeDownToRefrsh)holder.swipeRefreshLayout).canChildScrollUp(holder.staggeredGridView);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With