Get Installed Application in List view using Custom Adapter

          Some Times you may require user installed application in Android to perform certain task like Lock application or you may working on project which hide application or application like Task manager so this tutorial will help you to get all user installed application and sort them to display it. There are may ways to Display all application or only user installed apps with list view or Table view or you can use different layout for each Application to be display.
In this tutorial i am gone use following concept,
  1. List 
  2. PackageManager 
  3. Collections 
  4. BaseAdapter 
  5. PackageInfo

package com.androprogrammer.app1;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import android.os.Bundle;
import android.view.Menu;
import android.widget.ListView;

public class Main extends Activity {

 ListView apps;
 PackageManager packageManager;
    protected void onCreate(Bundle savedInstanceState) {
        apps = (ListView) findViewById(;
        packageManager = getPackageManager();
  final List <packageinfo> packageList = packageManager
    .getInstalledPackages(PackageManager.GET_META_DATA); // all apps in the phone
  final List <packageinfo> packageList1 = packageManager

    try {
      for (int n = 0; n < packageList.size(); n++) 

       PackageInfo PackInfo = packageList.get(n);
       if (((PackInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) != true) 
        //check weather it is system app or user installed app
          packageList1.add(packageList.get(n)); // add in 2nd list if it is user installed app 
           Collections.sort(packageList1,new Comparator <packageinfo >() 
             // this will sort App list on the basis of app name
            public int compare(PackageInfo o1,PackageInfo o2) 
             return o1.applicationInfo.loadLabel(getPackageManager()).toString()
                   .toString());// compare and return sorted packagelist.
        } catch (NullPointerException e) {
     } catch (Exception e) {
    Listadapter Adapter = new Listadapter(this,packageList1, packageManager);
package com.androprogrammer.app1;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class Listadapter extends BaseAdapter{

 List <packageinfo> packageList;
 Activity context;
 PackageManager packageManager;

 public Listadapter(Activity context, List <packageinfo> packageList,
   PackageManager packageManager) {
  this.context = context;
  this.packageList = packageList;
  this.packageManager = packageManager;

 private class ViewHolder {
  TextView apkName;

 public int getCount() {
  return packageList.size();

 public Object getItem(int position) {
  return packageList.get(position);

 public long getItemId(int position) {
  return 0;

 public View getView(final int position, View convertView, ViewGroup parent) {
  final ViewHolder holder;
  LayoutInflater inflater = context.getLayoutInflater();

  if (convertView == null) {
   convertView = inflater.inflate(R.layout.list_item, null);
   holder = new ViewHolder();

   holder.apkName = (TextView) convertView


  } else {
   holder = (ViewHolder) convertView.getTag();
  PackageInfo packageInfo = (PackageInfo) getItem(position);

  Drawable appIcon = packageManager
  String appName = packageManager.getApplicationLabel(
  appIcon.setBounds(0, 0, 40, 40);
  holder.apkName.setCompoundDrawables(appIcon, null, null, null);
  return convertView;






You can directly copy and paste above code in your project and it will give you all user installed apps in sorted order. This will look like this. Image of Application will be fetch and display dynamically so you are not require to take image view in list_item.xml. for this
Drawable appIcon = packageManager.getApplicationIcon(packageInfo.applicationInfo);
This will fetch icon from Packageinfo object and it will store in Drawable object.

i hope you may know some basic concept of java like List,collection etc. but in list view adapter android call Listadapter.getview() method each time and create view and then display it. if you scroll list view it will create view for next few elements of the list and garbage collector will clean old created views every time you scroll list view.

I hope this may be helpful to you and share it so it can be helpful to the others. if you have any doubts or any error then let me know.


  1. Can u give me Zip file of this example

    It don't Show any error but it can't run on emulatore

  2. It work perfect and help me So much
    Thank you very Much

  3. I used this to create a list view with check box.. But the problem is when i click a check box in first page, the same position is selected in next page also, automatically... Plz help me... Thanks in advance

    1. Hey i can't understand what you are explaining.
      can you put some code here or on pastebin so i can check and let you know
      it will be easy to understand.