1
我使用以下代碼獲取Android平板電腦上所有應用程序的列表,並按名稱按字母順序對其進行排序。應用程序排序列表
但由於某些原因,它不起作用 - 它保持不變。
//load apps
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final PackageManager pm = getActivity().getPackageManager();
final List<ResolveInfo> applist = pm.queryIntentActivities(mainIntent, 0);
//sort
Collections.sort(applist, new Comparator<ResolveInfo>(){
public int compare(ResolveInfo emp1, ResolveInfo emp2) {
return emp1.loadLabel(pm).toString().compareToIgnoreCase(emp2.loadLabel(pm).toString());
}
});
你'Comparator'期待權給我固定它。我在[GitHub]上有一個類似的例子(https://github.com/ggmathur/android-slide/blob/master/src/main/java/com/ggmathur/android/slide/AppSelectActivity.java#L114)。 – ggmathur