title: How to display installed app detail (label name, icon) in list view using array adapter?
body: <p>I am brand new to programming, and specially to android. I am trying to get all the installed application details, such as the label name and the icon to be displayed in a list view, and to launch it when a particular app is been clicked.. Currently I am trying to work with how to display them. i tried many of the source codes available in the net. Finally i ended up using this code which  I got from this site, <a href="http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-icon" rel="nofollow">http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-icon</a>. It seems to work but the output i get in the emulator is kind of weird.. </p>
  
  <p>I am kind of confused not knowing what to do.</p>
  
  <p>My code:</p>
  
  <pre><code>public class SecondPage extends ListActivity {
  
  private static final String TAG = "MyActivity" ;
  ListView lv;
  ArrayList al;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity);
      lv = getListView();
  
      al = getPackages();
     lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, al));
  
  }
  
  class PInfo {
      private String appname = "";
      private String pname = "";
      private String versionName = "";
      private int versionCode = 0;
      private Drawable icon;
      private void prettyPrint() {
          Log.v(TAG, appname + "\t " + pname + "\t " + versionName + "\t " + versionCode);
      }
  }
  
  private ArrayList&lt;PInfo&gt; getPackages() {
      ArrayList&lt;PInfo&gt; apps = getInstalledApps(false); /* false = no system packages */
      final int max = apps.size();
      for (int i=0; i&lt;max; i++) {
          apps.get(i).prettyPrint();
      }
      return apps;
  }
  private ArrayList&lt;PInfo&gt; getInstalledApps(boolean getSysPackages) {
      ArrayList&lt;PInfo&gt; res = new ArrayList&lt;PInfo&gt;();
      List&lt;PackageInfo&gt; packs = getPackageManager().getInstalledPackages(0);
      for(int i=0;i&lt;packs.size();i++) {
          PackageInfo p = packs.get(i);
          if ((!getSysPackages) &amp;&amp; (p.versionName == null)) {
              continue ;
          }
          PInfo newInfo = new PInfo();
          newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
          newInfo.pname = p.packageName;
          newInfo.versionName = p.versionName;
          newInfo.versionCode = p.versionCode;
          newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
          res.add(newInfo);
      }
      return res;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;ListView
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:id="@android:id/list"&gt;&lt;/ListView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And this is one line of the list view i get in the emulator:</p>
  
  <p><code>com.example.sample3.app.$PInfo@b3ec49c0</code></p>