-3

In my app I want to make a list of app icons using list view. I can get the app icon by using its package name. But I want to display the app icons(no text) on list view so how can I do that. Anyone help me.

This is the code I use to get the application icon.

Drawable icon= getPackageManager().loadApplicationIcon("package name");
image view.setDrawable(icon);

My question is how we can view the the application icons in list view.

Michael Spitsin
  • 2,539
  • 2
  • 19
  • 29
Adarsh
  • 105
  • 3
  • 14

2 Answers2

0
String pkg = "com.app.my";//your package name
Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg);
imageView.setImageDrawable(icon);

Check here for more details.

Community
  • 1
  • 1
Michael Spitsin
  • 2,539
  • 2
  • 19
  • 29
  • I know how to get application icon using package name .I want to know how we can store that icon in arrayList – Adarsh Jul 22 '16 at 16:34
  • Then the question must title like "How to display data in listView" and there are tons of tons tutorials, that explain how to do it – Michael Spitsin Jul 22 '16 at 16:53
  • Yaa I have seen that but I didn't find how to set drawable variable(the variable which contains all my app icons) with list view.Do you know how to do this – Adarsh Jul 22 '16 at 17:05
  • 1
    Simple. You need to create ListView, create adapter and create layout of item, then in getView you need to get image of item view via `findViewById` or `getTag` and then call `setImageDrawable` to it. – Michael Spitsin Jul 22 '16 at 17:20
  • 1
    Here is a tutorial of how you can work with list views http://www.vogella.com/tutorials/AndroidListView/article.html – Michael Spitsin Jul 22 '16 at 17:20
  • 1
    OK thanks a lot for your time and for your help I will go through this link:) – Adarsh Jul 23 '16 at 01:05
0

You can set app icon like below get using package name of any app installed.

           Drawable iccon = mContext.getPackageManager().getApplicationIcon(
                    pkg);
            icon.setBackground(null);
            icon.setImageDrawable(iccon);
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41