views:

61

answers:

1

I am building an app that will be an Android listview. Each listview object will be a title and a few sub-categories and ratings. I would like the user to be able to sort the listview by these ratings or sub-categories. Thank you in advance.

A: 

You need to provide some UI for letting the user pick the sorting (perhaps a dialog from the options menu?). From there it depends on the kind of adapter you're using to populate the listview.

If you're using a CursorAdapter, re-query with the new sorting and call changeCursor on the adapter.

If you're using an ArrayAdapter, you can call sort on the adapter and pass a comparator.

dhaag23
I'm very new to this, so what would be the advantages of using either of those options? What are the context and cursor for CursorAdapter and what is the comparator for ArrayAdapter? Is it an array that you can sort by like rating array?
AF_Aggie
You pose a number of basic questions and should probably read up a bit on these subjects, starting with android app fundamentals (http://developer.android.com/guide/topics/fundamentals.html). Briefly: you would use a cursor adapter when getting items from a database. A cursor is the way you traverse a database result set. You'd use an array adapter in most other cases, in particular when you know the data to be shown ahead of time.
dhaag23