安装的应用程序的Alphabatize名单 [英] Alphabatize list of installed apps
问题描述
您好我跟着下面的教程,并成功上市我所有的应用程序安装在我的应用程序。
不过它不会列出按字母顺序,我可以不知道如何对它们进行排序,使他们。任何帮助,这将大大AP preciated。我试着像这样的一些事情
类IgnoreCaseComparator实现比较<字符串> {
公众诠释比较(STRA字符串,字符串STRB){
返回strA.compareToIgnoreCase(STRB);
}
}
IgnoreCaseComparator ICC =新IgnoreCaseComparator();
java.util.Collections.sort(SomeArrayList,ICC);
但无法弄清楚如何将其应用到应用程序列表的标题。谢谢你的帮助,这
===编辑===
感谢您的回复我做了以下,但有一个错误的排序。错误读取在类型类别的方法的排序(列表,比较器)是不适用的参数(列表,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));
返回应用程序;
}
当您查询的Android让安装的应用程序的列表,你会得到一个名单,其中,ApplicationInfo>
。安卓提供一个 ApplicationInfo.DisplayNameComparator
对于那些:
Collections.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
).
这篇关于安装的应用程序的Alphabatize名单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!