iT邦幫忙

第 12 屆 iThome 鐵人賽

0
自我挑戰組

30 天開發 Android App 的流水帳系列 第 32

Day 32:來呼叫星戰 Profile List 下一頁吧(1/2)

  • 分享至 

  • twitterImage
  •  

在 Day 31 分享 RecyclerView 如何載入更多之後,先來幫大家回顧之前星戰的 Profile List 回傳格式。

{
  "count": 82,
  "next": "http://swapi.dev/api/people/?page=2",
  "previous": null,
  "results": [
  ]
}

其中,next & previous 是一個網址,跟官方網站對照嫁接 API 的 domain 其實可以知道 page 就是 api 的取得頁數的參數

https://ithelp.ithome.com.tw/upload/images/20201014/20130546uUehHtvKdq.png

回到 MainPresenter 先試試 page = 1 時,是不是跟原先的資料相同

val call = NetworkManager.client.profileList(1)
call.enqueue(object : NetworkCallback<ProfileListResponse>() {
    override fun onSuccess(response: ProfileListResponse) {
        view.showProfileList(response.results)
    }

    override fun onFailure(
        call: Call<ProfileListResponse>,
        statusCode: Int,
        errorBody: ResponseBody?
    ) {
        view.showApiError("statusCode= $statusCode & errorBody= $errorBody")
    }
})

上一篇
Day 31:RecyclerView Loads More
系列文
30 天開發 Android App 的流水帳32
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言