【问题标题】:Call API based on page count根据页数调用 API
【发布时间】:2018-02-09 12:37:27
【问题描述】:

请帮我解决基于 Wordpress rest api 中页数的 api 调用。 http://www.thejavaprogrammer.com/wp-json/wp/v2/posts?page=1&per_page=10

正如我从下面的链接中阅读的分页:- http://blog.iamsuleiman.com/android-pagination-tutorial-getting-started-recyclerview/

所以请告诉我任何解决方案。

【问题讨论】:

  • 你的手段是什么?
  • 表示你有你的问题在你的脑海中,但在上面的问题中没有
  • 假设页数为 5,那么它将在回收站视图中加载 50 个项目。我想根据页数获取或调用 api 并在回收站视图中加载这些项目。
  • 那么你需要根据你的页面增加你的计数
  • 最初它会加载 10 个项目,然后在拉动刷新时逐页增加项目

标签: android android-recyclerview pagination android-volley


【解决方案1】:

因此,每当您尝试访问 api 并根据需要进行计算时,您都需要增加变量的计数:-

int count = 0;
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    int visibleItemCount = layoutManager.getChildCount();
    int totalItemCount = layoutManager.getItemCount();
    int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();

    if (!isLoading() && !isLastPage()) {
        if ((visibleItemCount + firstVisibleItemPosition) >= totalItemCount
                && firstVisibleItemPosition >= 0) {
            count++;
            loadMoreItems();

        }
    }
}

public void loadMoreItems() {
    int numberPage = count * 10;
    String url = "http://www.thejavaprogrammer.com/wp-json/wp/v2/posts?page=1&per_page="+numberPage;
}

或者你可以增加简单的 10 个计数。

int count = 0;
public void loadMoreItems() {
     count = count + 10;
     String url = "http://www.thejavaprogrammer.com/wp-json/wp/v2/posts?page=1&per_page="+count;
}

【讨论】:

    猜你喜欢
    • 2019-08-13
    • 1970-01-01
    • 2021-07-30
    • 2019-10-14
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 2022-06-20
    • 1970-01-01
    相关资源
    最近更新 更多