【问题标题】:how do i execute this @get...@Query snippet correctly?我如何正确执行这个@get...@Query 片段?
【发布时间】:2018-03-22 09:52:54
【问题描述】:
@GET("comments?_sort=id&_order=desc&_limit=5&_page={pageNumber}")

Call<java.util.ArrayList<ImgRepo>>fetchNewData (@Path("pageNumber") int pageNumber);

【问题讨论】:

标签: android json android-studio


【解决方案1】:

要使用 Retrofit 调用,您首先必须创建一个 Call 对象,然后执行它的 enqueue() 方法,然后处理回调,如下所示:

Call<List<ImgRepo>> call = YourServiceClass.fetchNewData(number);

call.enqueue(new Callback<List<ImgRepo>>() {
      @Override
      public void onResponse(Call<List<ImgRepo>> call, Response<List<ImgRepo>> response) {
        ArrayList<ImgRepo> myData = response.body();
        //Handle success
      }

      @Override
      public void onFailure(Call<List<ImgRepo> call, Throwable t) {
        // handle failure
      }
    });

我建议您查看本教程以获取更多信息:https://zeroturnaround.com/rebellabs/getting-started-with-retrofit-2/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 2011-11-05
    • 1970-01-01
    • 2020-02-16
    • 2021-02-07
    • 1970-01-01
    相关资源
    最近更新 更多