Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To display your activities' names correctly in the list, you should override the <code>getView</code> method of your <code>ListAdapter</code>, and set some of your local variables as final (to work with inner class):</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final PackageManager pm = this.getPackageManager(); Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); final ArrayList&lt;ResolveInfo&gt; list = (ArrayList&lt;ResolveInfo&gt;) pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED); for (ResolveInfo rInfo : list) { Log.i(TAG, ": Installed Applications " + rInfo.activityInfo. applicationInfo.loadLabel(pm).toString()); } final ArrayAdapter&lt;ResolveInfo&gt; adapter = new ArrayAdapter&lt;ResolveInfo&gt;(this, R.layout.list_item, list) { @Override public View getView(int position, View convertView, ViewGroup parent) { convertView = super.getView(position, convertView, parent); final String text = list.get(position).activityInfo. applicationInfo.loadLabel(pm).toString(); ((TextView)convertView).setText(text); return convertView; } }; setListAdapter(adapter); ListView lv = getListView(); lv.setTextFilterEnabled(true); } </code></pre> <p>This way you have your custom <code>ArrayAdapter</code> implementation, which displays the proper label of applicationinfo in the <code>TextView</code>.</p> <p>You can also achieve this, if you create a new <code>ArrayList&lt;String&gt;</code>, and populate it inside the for cycle where you log the applications: </p> <pre><code>final ArrayList&lt;String&gt; labelList = new ArrayList&lt;String&gt;(); for (ResolveInfo rInfo : list) { Log.i(TAG, ": Installed Applications " + rInfo.activityInfo. applicationInfo.loadLabel(pm).toString()); labelList.add(rInfo.activityInfo. applicationInfo.loadLabel(pm).toString()); } final ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, labelList); setListAdapter(adapter); </code></pre> <p>Then you use this new <code>labelList</code> as the source of your <code>adapter</code>.</p> <p><strong>Update</strong><br /> To include the icon into the item renderers, the overridden <code>getView</code> method would look like:</p> <pre><code>@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) convertView = LayoutInflater.from(parent.getContext()). inflate(R.layout.list_item, parent, false); final String text = list.get(position).activityInfo. applicationInfo.loadLabel(pm).toString(); ((TextView)convertView.findViewById(R.id.text)).setText(text); final Drawable drawable = list.get(position).activityInfo.applicationInfo.loadIcon(pm); ((ImageView)convertView.findViewById(R.id.image)).setImageDrawable(drawable); return convertView; } </code></pre> <p>and your <code>res/layout/list_item.xml</code> layout file has to contain the <strong><code>text</code></strong> <code>TextView</code> and the <strong><code>image</code></strong> <code>ImageView</code>: </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="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;ImageView android:id="@+id/image" android:layout_width="50dp" android:layout_height="50dp" /&gt; &lt;TextView android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10dp" android:textSize="16sp" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload