本文介绍了如何整理List< PackageInfo>在android ..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

List<PackageInfo> pkginfoList = getPackageManager()
                .getInstalledPackages(0);

如何排序 PackageInfo ,我做了 ApplicationInfo 运行正常

How to Sort the PackageInfo, i did ApplicationInfo thats working fine

Collections.sort(installedList, new ApplicationInfo.DisplayNameComparator(packageManager));

但我想实现 PackageInfo 也..

我不知道怎么做..请任何人帮助我......!

i'm not sure how to do.. Please any one help me...!

推荐答案

方法有两个参数:


  1. 列表你想要排序

  2. 并且对象,用于比较类型是列表中元素类型的元素。

  1. The list you want to sort
  2. And a Comparator object used to compare elements which type is the type of elements in your list.

在您的情况下你想实现一个比较器< PackageInfo> 。假设 PackagInfo 的示例有一个 getName()方法:

In your case you want to implement a Comparator<PackageInfo>. An example supposing a PackagInfo has a getName() method:

new Comparator<PackagInfo>() {
    @Override
    public int compare(PackagInfo arg0, PackagInfo arg1) {
      return arg0.getName().compareTo(arg1.getName());
    }
 };

另一个解决方案是从某处获得一个,但我不熟悉Android。查看您提供的代码段,也许您有一个PackageInfo.xxxx静态字段,其类型为 Comparator< PackageInfo>

Another solution is to get one from somewhere but I don't know Android well. Looking at the piece of code you provided, maybe you have a PackageInfo.xxxx static field which type is Comparator<PackageInfo> ?

这篇关于如何整理List&lt; PackageInfo&gt;在android ..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 09:03