安装的应用程序的Alphabatize名单应用程序、名单、Alphabatize

2023-09-05 04:34:27 作者:逍遥叹

您好我跟着下面的教程,并成功上市我所有的应用程序安装在我的应用程序。

列表样式的所有安装的应用程序

不过它不会列出按字母顺序,我可以不知道如何对它们进行排序,使他们。任何帮助,这将大大AP preciated。我试着像这样的一些事情

 类IgnoreCaseComparator实现比较<字符串> {
            公众诠释比较(STRA字符串,字符串STRB){
                返回strA.compareToIgnoreCase(STRB);
            }
        }
        IgnoreCaseComparator ICC =新IgnoreCaseComparator();
        java.util.Collections.sort(SomeArrayList,ICC);
 

但无法弄清楚如何将其应用到应用程序列表的标题。谢谢你的帮助,这

===编辑===

visual studio 2012 写好C 程序源代码,运行后看不到命令提示符里面的结果

感谢您的回复我做了以下,但有一个错误的排序。错误读取在类型类别的方法的排序(列表,比较器)是不适用的参数(列表,ApplicationInfo.DisplayNameComparator)

 私人列表<应用> loadInstalledApps(布尔includeSysApps){
      名单<应用>应用程序=新的ArrayList<应用>();

      PackageManager packageManager = getPackageManager();

      名单< PackageInfo>包= packageManager.getInstalledPackages(0);

      的for(int i = 0; I< packs.size();我++){
         PackageInfo p值= packs.get(ⅰ);
         ApplicationInfo A = p.applicationInfo;
         如果((includeSysApps)及!及((a.flags&安培; ApplicationInfo.FLAG_SYSTEM)== 1)){
            继续;
         }
         应用程序=新的应用程序();
         app.setTitle(p.applicationInfo.loadLabel(packageManager)的ToString());
         app.setPackageName(p.packageName);
         app.setVersionName(p.versionName);
         app.setVersion code(p.version code);
         CharSequence的描述= p.applicationInfo.loadDescription(packageManager);
         app.setDescription(说明​​= NULL description.toString():!?);
         apps.add(应用程序);
      }
      Collections.sort(应用程序,新的ApplicationInfo.DisplayNameComparator(packageManager));
      返回应用程序;
   }
 

解决方案

当您查询的Andr​​oid让安装的应用程序的列表,你会得到一个名单,其中,ApplicationInfo> 。安卓提供一个 ApplicationInfo.DisplayNameComparator 对于那些:

  Col​​lections.sort(应用程序,新的ApplicationInfo.DisplayNameComparator(PM));
 

(其中是一个实例 PackageManager )。

Hi I followed the below tutorial and successfully listed all of my installed apps in my application.

List all installed apps in style

However it does not list them alphabetically and i can not figure out how to sort them so that they are. Any help with this would be greatly appreciated. I've tried a few things like this

class IgnoreCaseComparator implements Comparator<String> {
            public int compare(String strA, String strB) {
                return strA.compareToIgnoreCase(strB);
            }
        }
        IgnoreCaseComparator icc = new IgnoreCaseComparator();
        java.util.Collections.sort(SomeArrayList,icc);

But can't figure out how to apply it to the app list titles. Thank you for any help with this

===EDIT===

Thank you for the reply I did the following but have an error on sort. The error reads "The method sort(List, Comparator) in the type Collections is not applicable for the arguments (List, ApplicationInfo.DisplayNameComparator)"

   private List<App> loadInstalledApps(boolean includeSysApps) {
      List<App> apps = new ArrayList<App>();

      PackageManager packageManager = getPackageManager();

      List<PackageInfo> packs = packageManager.getInstalledPackages(0); 

      for(int i=0; i < packs.size(); i++) {
         PackageInfo p = packs.get(i);
         ApplicationInfo a = p.applicationInfo;
         if ((!includeSysApps) && ((a.flags & ApplicationInfo.FLAG_SYSTEM) == 1)) {
            continue;
         }
         App app = new App();
         app.setTitle(p.applicationInfo.loadLabel(packageManager).toString());
         app.setPackageName(p.packageName);
         app.setVersionName(p.versionName);
         app.setVersionCode(p.versionCode);
         CharSequence description = p.applicationInfo.loadDescription(packageManager);
         app.setDescription(description != null ? description.toString() : "");
         apps.add(app);
      }
      Collections.sort(apps, new ApplicationInfo.DisplayNameComparator(packageManager));
      return apps;
   }

解决方案

When you query Android to get the list of installed applications, you will get a List<ApplicationInfo>. Android supplies an ApplicationInfo.DisplayNameComparator for those:

Collections.sort(apps, new ApplicationInfo.DisplayNameComparator(pm)); 

(where pm is an instance of PackageManager).