Android sort ListView alphabetically

前端 未结 8 1164
后悔当初
后悔当初 2020-12-05 03:10

So I\'m trying to sort a simple ArrayAdapter for ListView. Here\'s what I\'ve tried:

ListView lv;
String[] months = {
        \"January\",
              


        
8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 03:28

    To sort a list, you need to use a Comparator. You need to sort the underlying collections using a comparator that does alphabetical sorting and then notify the list to update itself.

    Here's an example of doing this using an ArrayAdapter : https://stackoverflow.com/a/8920348/1369222

提交回复
热议问题