Android : converting string listview to custom listview

on Monday, March 23, 2015


I've created a listview which shows all currently installed apps on the android device. The code also retrieves the icon of the app, but I cannot display it within the list because it can only display strings. How can I alter my code so that it also displays the app icon next to the name?


additionally after I do this I also want to add a checkbox next to each app title and icon



final ArrayList<String> list = new ArrayList<String>();


final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities( mainIntent, 0);
for (Object object : pkgAppsList)
{
ResolveInfo info = (ResolveInfo) object;
Drawable icon = getBaseContext().getPackageManager().getApplicationIcon(info.activityInfo.applicationInfo);
String strAppName = info.activityInfo.applicationInfo.publicSourceDir.toString();
String strPackageName = info.activityInfo.applicationInfo.packageName.toString();
final String title = (String)((info != null) ? getBaseContext().getPackageManager().getApplicationLabel(info.activityInfo.applicationInfo) : "???");
list.add(title);
}

final ListView listview = (ListView) findViewById(R.id.listView);
final ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, list);
listview.setAdapter(adapter);


thanks


0 comments:

Post a Comment