Android的:如何订购的ArrayList< HashMap的<字符串,字符串>>?字符串、ArrayList、Android、LT

2023-09-06 01:12:42 作者:你曾是照耀我的倾城日光

我在节能产品的详细信息在地图和ArrayList的&LT增加; HashMap的<字符串,字符串>>和一个自定义列表适配器的设置。我需要在它通过价格的值进行排序。如何实现呢?先谢谢了。

I'm saving details of product in a map and adding in ArrayList< HashMap< String,String >> and setting in to a custom list adapter. I need to sort the values by price in it. How to achieve it? Thanks in advance.

推荐答案

普莱斯使用下面的code:

Pleas use the code below :

ArrayList< HashMap< String,String >> arrayList=populateArrayList();
    Collections.sort(arrayList, new Comparator<HashMap< String,String >>() {

        @Override
        public int compare(HashMap<String, String> lhs,
                HashMap<String, String> rhs) {
            // Do your comparison logic here and retrn accordingly.
            return 0;
        }
    });