I have a listview, which I would like to sort in an alphabetic order. How do I do that?
public class AppDrawer extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
getSupportActionBar().hide();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app_drawer);
ListView userInstalledApps = (ListView) findViewById(R.id.installed_app_list);
List<AppList> installedApps = getInstalledApps();
AppAdapter installedAppAdapter = new AppAdapter(this, installedApps);
userInstalledApps.setAdapter(installedAppAdapter);
}
private List<AppList> getInstalledApps() {
List<AppList> res = new ArrayList<AppList>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
if ((isSystemPackage(p) == false)) {
String appName = p.applicationInfo.loadLabel(getPackageManager()).toString();
Drawable icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(new AppList(appName, icon));
}
}
return res;
}
private boolean isSystemPackage(PackageInfo pkgInfo) {
return ((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true : false;
}