Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues Displaying a ListView of All Installed Apps and Implementing an OnItemClickListener
    primarykey
    data
    text
    <p>I am trying to write a very simple app that displays the name of every installed app on the device in a listview. I am using Google's ListView tutorial as a base.</p> <p>Here is my code:</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) { 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; } }; setListAdapter(adapter); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // On Item Click Activity // This is where I want to send the Package Name of the app selected to be passed to a method. } }); } &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> <p>UPDATE: I now need to use an OnItemClickListener to pass the Package Name of the App selected to a method.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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