排序Android应用字母? [英] Sort Android apps alphabetically?

查看:96
本文介绍了排序Android应用字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

packageManager = getPackageManager();
    List<PackageInfo> packageList = packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
    List<PackageInfo> installedapps = new ArrayList<PackageInfo>();

    for(PackageInfo apps: packageList){
        if(!isSystemPackage(apps)){
            installedapps.add(apps);
        }
    }


   Collections.sort(installedapps, new Comparator<PackageInfo>(){
        public int compare(PackageInfo o1, PackageInfo o2) {
            return o1.packageName.compareTo(o2.packageName);
        }
    });



    apkList = (ListView) findViewById(R.id.listView);
    apkList.setAdapter(new AppInfoAdapter(this, installedapps, packageManager));

installedapps是设备减去系统应用上的所有应用程序的列表。我想这样做的唯一一件事就是那种按字母顺序,也不能完全弄清楚如何。

installedapps is a list of all the apps on the device minus the system apps. The only thing I want to do is sort them alphabetically, can't quite figure out how.

推荐答案

这我明白,要排序 PackageInfo 名单按名称的字母顺序对象。我将开始<一个href=\"http://stackoverflow.com/questions/2784514/sort-arraylist-of-custom-objects-by-property\">here.你想要做的是为你创建一个名为 installedapps ,然后排序使用ArrayList的自定义比较 Col​​lections.sort(..) PackageInfo ,你应该进行排序使用该属性是 p.packageName 这是应用程序的完全限定域名(您可以使用常规的前pressions到最后一块包名的隔离)。隔离应用的美容特性的一个例子,你可以找到<一个href=\"http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-icon\"相对=nofollow>这里。

From what I understand, you want to sort a list of PackageInfo objects alphabetically by name. I would start here. What you want to do is create a custom Comparator for the ArrayList you called installedapps and then sort is using Collections.sort(..). The property of PackageInfo you should use for sorting is p.packageName which is the fully qualified name of the Application (you can use regular expressions to isolate the last piece of the package name). An example of isolating cosmetic properties of apps you can find here.

这篇关于排序Android应用字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆