I saw this question. The answer at this question is workable. BUT... I have to create scrolling to both of sides. This answer has helped me with reaching bottom, but I don't know how to send request when I reach top of the list. I tried to use smth like that:
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if(dy > 0) //check for scroll down
{
}
}
});
and added this:
if(dy == 0)
{
getting some data
}
but it works wrongly. Why? Because after loading some data after reaching bottom of the list, my list automatically reach the top of the list and data loading again. So I have to add one more condition but I don't imagine which one. Maybe someone can help me?
UPDATE
I tried to add smth like that:
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) //check for scroll down
{
pastVisiblesItems = layoutManager.findFirstVisibleItemPosition();
if (loading) {
loading = false;
}
}
if(pastVisiblesItems==5){
loading=true;
}
if (loading&&recyclerView.canScrollVertically(-1)){
if (prev_url != null) {
Log.i("m","[]");
}
}
}
});
but this condition:
if (loading&&recyclerView.canScrollVertically(-1)){
if (prev_url != null) {
Log.i("m","[]");
}
}
will send ~30 requests and it will be wrong for me :(