Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ParseQueryAdapter pagination with RecyclerView.Adapter

I am trying to implement CardView in a list using RecyclerView.Adapter. Creating cards in a list was pretty straightforward using RecyvlerView.Adapter. I am using parse.com as my back end so queries for cards data are made using its APIs. Now I want to add pagination to this list. If I use Parse's ParseQueryAdapter, I can get built in pagination from that API. But then I would have to ditch RecyclerView.Adapter (or not?) and fall back to old BaseAdapter method. However, I don't want to do that and work with this new RecyclerView.Adapter provided by Android (because of the efficiency it promises).

My question: What is the better approach?

  1. Use ParseQueryAdapter with old BaseAdapter method
  2. Use RecyclerView.Adapter with normal data fetch method and write my own pagination
like image 423
Jazib Avatar asked Nov 10 '22 18:11

Jazib


1 Answers

You can try making a shim between the two adapters. It would extend RecyclerView.Adapter and contain a ParseQueryAdapter. Then it basically just proxies all the methods. So, for example, the onBindViewHolder just calls the ParseAdapter.getItemView. The tricky part is setting up the listener for when the parse data comes down, using addOnQueryLoadListener, and having it trigger a refresh of the RecyclerView.

Here's a stub: https://gist.github.com/mrowl/0ab027b5f84e25f51102

It seems to work for the basic case, but it can probably be improved upon significantly. I'm pretty new to this side of the api.

like image 147
mrowl Avatar answered Nov 15 '22 07:11

mrowl