Please excuse my English, I'm French...
So, I've got a question for my Android App. I've to integrate a grid view as Pinterest style. I found this lib : Staggered Grid View (https://github.com/maurycyw/StaggeredGridView)
It's work fine but... There is no OnScrollListener ! I had to know when the user see the last item, in order to load more. But it's not possible without OnScrollListener !
Have you got an idea for my problem ?
Thanks a lot.
Try this if nothing works for you then wrap your recycler view in a scroll view and then check if scroll view has reached its bottom:
In your xml file:
In your class file:
Remember to set nested scrolling of recycler view to false for smooth scrolling in your class file:
If you want to start loading next page just before it reaches the bottomm, then just subtract an integer from mScrollView.getChildAt(0).getBottom()
For example 1000 is subtracted here:
Use a greater integer to start loading much before the scroll reaches bottom.
To know when the last item is shown on the screen, i use the Adapter's getView() method. Just compare your last index with the "position" parameter. Something like this
and maybe then you would like to see this: How to add data into bottom of Android StaggeredGridView and not go back top? to avoid load the list from the begining and continue from the last item shown.
i hope this helps, don't know if it's the best solution, but is working for me ;)
Why would you use onScrollListener for that? Instead, write a class (MyStaggeredGridAdapter, perhaps?) that extends BaseAdapter and apply it to the StaggeredGridView. Then you can use the adapter's getView() method, which will be called whenever a new view needs to be rendered.
UPDATE:
After testing,
Calling
notifyDataSetChanged()
forStaggeredGridView Adapter
case to reset the scroll position to 0 (Start of the Views).Instead use PinterestLikeAdapterView
I have add
loadMoreListener
to theStaggeredGridView
steps:
1- add a loadmore Interface and booelan isLoading (at the top of the class)
2- find
trackMotionScroll
function, in the else ofdeltaY > 0
and after the
up = false;
add3- add
setListener()
andloadComplated()
functionsHOW to use:
1- define a
loadMoreListener
in yourActivity/Fragment
2- when you done data loading and add it to the adapter call