3

The UI of the app looks like this, and can contain a moderately large amount of data (a few hundred products, tens of categories). The products strips scroll left to right. The entire UI scrolls vertically.

Category 1
   Product 1    Product 2    Product 3    Product 4    <-- scrolls -->

Category 2
   Product 1    Product 2    Product 3    Product 4    <-- scrolls -->

Category 3
   Product 1    Product 2    Product 3    Product 4    <-- scrolls -->

I've implemented the horizontal scrolling product sections (within each category) as RecyclerViews. The vertically scrolling (containing the product sections) is implemented within a vertically scrolling RecyclerView. With simple dummy data from SQL it works fine and performance is good.

But to use real data I need each section to show its own subset of products. It seems desirable to run one query to get a products Cursor (CursorLoader) to provide access to ALL the products, across all the categories and then to use a filter on that cursor to display just the products for one category in each horizontal, products RecyclerView.

I am using this https://gist.github.com/Shywim/127f207e7248fe48400b which is a CursorRecyclerAdapter. It works well so far, and supports filtering, but I am unable to see how to implement filtering. I have found some samples for FilterQueryProvider but they seem to have significant performance implications as it seems as if it requires re-running the query again. I'm wondering if my approach is fundamentally sensible.

In my research I also found devs recommending no-one use FilterQueryProvider and to use CursorLoader instead, but if I'm relying on CursorLoader how do I implement it without a whole series of inefficient queries to populate the rows of the UI? I can't help thinking there must be a way to do one products query and filter that cursor for each row.

TLDR; In a scenario with one fairly large data set that needs displaying in subsets in various Cursor-backed Views, what approach is best in order to sub-divide the data into "sub-Cursors" whilst retaining good performance and efficiency?

UPDATE. Since posting this it occurs to me that in advance of querying for the products I need to know which categories I need to display - so I expect there to be two queries, performed in series. The app is in a kiosk setting with one device type, no screen rotations, and one app running so config changes are not a concern. So I think I can use an AsyncTask to run the first query to get a list of categories (containing products), and then run a query (using each Category ID) to get a cursor of products for each category. So far this is the best approach I've come up with, there must be a better way not least because I don't want to run lots of queries, especially when most are not useful until the user scrolls down the page.

Ollie C
  • 28,313
  • 34
  • 134
  • 217
  • Hi Ollie, you may have gone down these avenues of thought, but if not (if it isn't helpful let me know and I'll delete the comment): 1) I much prefer the `RecyclerView` way of doing things, you can post off another `AsyncTask` to deal with executing a query for each of the CatagoryID's (in order of what is shown first) and then fill out the correct `RecyclerView`. 2) Use the one query `SELECT * FROM X WHERE catID = Y OR catID = Z...` and process the results based on catagories or ORDER them depending on how they are show. Hope it helps, even if a little bit. – Chris Handy Feb 02 '15 at 12:18
  • I know it's a bit late :) but maybe could help others, check this: http://stackoverflow.com/questions/29792187/add-a-search-filter-on-recyclerview-with-cards – Valentino Mar 21 '16 at 10:18

0 Answers0