java - Alphabetize List of Installed Apps -
i have list of users installed applications , want come out alphabetized (not on dividers or alphabetized) looked around haven't found (it has been dividers). feel should simple thing haven't been able figure out. here code:
utilities.java:
package com.example.awesomefilebuilderwidget; imports public class utilities { /* * installed application on mobile , return list * @param c context of application * @return list of installed applications */ public static list<resolveinfo> getinstalledapplications(context c) { intent intent = new intent(intent.action_main); intent.addcategory(intent.category_launcher); return c.getpackagemanager().queryintentactivities(intent, packagemanager.get_activities); }
appinfoadapter.java:
package com.example.awesomefilebuilderwidget; imports public class appinfoadapter extends baseadapter implements filterable { private context mcontext; private list<resolveinfo> mlistappinfo; private packagemanager mpackmanager; private list<resolveinfo> originallistappinfo; public appinfoadapter(context c, list<resolveinfo> listapp, packagemanager pm) { mcontext = c; this.originallistappinfo = this.mlistappinfo = listapp; mpackmanager = pm; log.d("appinfoadapter", "top"); } @override public int getcount() { log.d("appinfoadapter", "getcount()"); return mlistappinfo.size(); } @override public object getitem(int position) { log.d("appinfoadapter", "getitem"); return mlistappinfo.get(position); } @override public long getitemid(int position) { log.d("appinfoadapter", "getitemid"); return position; } @override public view getview(final int position, view convertview, viewgroup parent) { // selected entry final resolveinfo entry = (resolveinfo) mlistappinfo.get(position); // reference convertview view v = convertview; // inflate new layout if null if (v == null) { layoutinflater inflater = layoutinflater.from(mcontext); v = inflater.inflate(r.layout.layout_appinfo, null); log.d("appinfoadapter", "new layout inflated"); } // load controls layout resources imageview ivappicon = (imageview) v.findviewbyid(r.id.ivicon); textview tvappname = (textview) v.findviewbyid(r.id.tvname); textview tvpkgname = (textview) v.findviewbyid(r.id.tvpack); final checkbox addcheckbox = (checkbox) v .findviewbyid(r.id.addcheckbox); log.d("appinfoadapter", "controls layout resources loaded"); // set data display ivappicon.setimagedrawable(entry.loadicon(mpackmanager)); tvappname.settext(entry.activityinfo.loadlabel(mpackmanager)); tvpkgname.settext(entry.activityinfo.packagename); }
drag_and_drop_app:
// create new adapter adapter = new appinfoadapter(this, (list<resolveinfo>) utilities.getinstalledapplications(this), getpackagemanager()); // load list application mlistappinfo = (listview)findviewbyid(r.id.lvapps); // set adapter list view mlistappinfo.setadapter(adapter);
so best way alphabetize list?
updated:
final answer:
public static arraylist<resolveinfo> getinstalledapplications(context c) { intent intent = new intent(intent.action_main); intent.addcategory(intent.category_launcher); final packagemanager pm = c.getpackagemanager(); arraylist<resolveinfo> applist = (arraylist<resolveinfo>) c.getpackagemanager().queryintentactivities(intent, packagemanager.get_activities); collections.sort(applist, new comparator<resolveinfo>(){ public int compare(resolveinfo emp1, resolveinfo emp2) { return emp1.loadlabel(pm).tostring().comparetoignorecase(emp2.loadlabel(pm).tostring()); } }); return applist; }
not tested:
public static arraylist<resolveinfo> getinstalledapplications(context c) { intent intent = new intent(intent.action_main); intent.addcategory(intent.category_launcher); arraylist<resolveinfo> applist = c.getpackagemanager().queryintentactivities(intent, packagemanager.get_activities); collections.sort(applist, new comparator<resolveinfo>(){ public int compare(resolveinfo emp1, resolveinfo emp2) { return emp1.loadlabel(pm).tostring().comparetoignorecase(emp2.loadlabel(pm).tostring()); } }); return applist;
}
Comments
Post a Comment