开发者

How to Sort a Listview by a category

开发者 https://www.devze.com 2023-01-17 14:51 出处:网络
I am building an app that will be an Android listview. Each listview object will be 开发者_StackOverflow中文版a title and a few sub-categories and ratings. I would like the user to be able to sort the

I am building an app that will be an Android listview. Each listview object will be 开发者_StackOverflow中文版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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消