Answer the question
In order to leave comments, you need to log in
RecyclerView pagination?
Hello guys what is the problem here.
//MainActivity.java
private int previousTotal = 0;
private boolean loading = true;
private int visibleThreshold = 5;
int firstVisibleItem, visibleItemCount, totalItemCount;
private int currentPage = 0;
@Override
public onCreate(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
listView = (RecyclerView) findViewById(R.id.recycler);
listView.addOnScrollListener(new RecyclerView.OnScrollListener()
{
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
{
super.onScrolled(recyclerView, dx, dy);
visibleItemCount = recyclerView.getChildCount();
totalItemCount = layoutManager.getItemCount();
firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
if (loading)
{
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
currentPage++;
}
}
if (!loading && (totalItemCount - visibleItemCount)
<= (firstVisibleItem + visibleThreshold)) {
// End has been reached
load();
loading = true;
}
}
});
this.load();
}
protected void loadI()
{
Call<list> call = api().list(10 * currentPage);
call.enqueue(new Callback<UserItems>()
{
@Override
public void onResponse(Call<list> call, Response<list> response)
{
if(response.isSuccessful())
{
for (Items item : response.body().items())
{
Log.d("items", String.valueOf(item.id()));
}
}
adapter.notifyDataSetChanged();
}
@Override
public void onFailure(@NonNull Call<UserItems> call, @NonNull Throwable t) {
Log.d("error_messages", "Данные не получены");
}
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question