Android How to create pagination with number

Viewed 1227

I'm quite new with android and code with kotlin. I'm queering data from api call using Retrofit and I'm trying to populate that data into RecyclerView list. I'm familiar with basic Api call and populating data to Recyclerview Adapter.

But now I'm trying to make pagination and I came across Paging library. I tried to look around on how to create pagination and come across with multiple of good tutorial for that.

Most all PagedListAdapter example I saw is endless scrolling. I'm trying to create a pagination with numbers like this instead:

enter image description here

I want to limit the page with only around 20 data and the number of page will depends on the total number of data fetched from the api.

My api get call is as this, where I can set data per page and query the data based on page number

@GET("/api/data/history")
fun getDataHistory(
    @Query("cardNo") cardNo: String?,
    @Query("perPage") perPage: Int?,       //data per page
    @Query("pageNumber") pageNumber: Int?  //page number
): Call<DataHistory>

Response data:

{ 
  "metaData" : { 
    "totalCount": 150,  // ( maximum 200 ) 
    "perPage": 10,      // ( default 20 ) 
    "pageNumber": 3     // ( default 1 )  
  },
  "data" : [
    {
      "statementDate": null,
      "transactionDate": "2020-02-20 10:22:32",
      "postingDate": "2020-02-20",
      "cardNo": "70838153000829349",
      "stan": "0",
      "qty": 10.000,
      "totalAmount": 24.00
    },
    ...
  ]
}

Is it still relevant for me to use Paging library? How should I tackle this issue?

Thanks in advance.

0 Answers
Related