Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4627466
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:34:19+00:00 2026-05-22T03:34:19+00:00

I am trying to write a very simple app that displays the name of

  • 0

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.

Here is my 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<ResolveInfo> list =
                (ArrayList<ResolveInfo>) pm.queryIntentActivities(intent, 
                        PackageManager.PERMISSION_GRANTED);
        for (ResolveInfo rInfo : list)
        {
            Log.i(TAG, ": Installed Applications " + rInfo.activityInfo.
                    applicationInfo.loadLabel(pm).toString());
        }

        final ArrayAdapter<ResolveInfo> adapter = 
            new ArrayAdapter<ResolveInfo>(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<?> 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.


            }
          });
    }




 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView android:id="@+id/image" 
        android:layout_width="50dp" android:layout_height="50dp" />
    <TextView android:id="@+id/text"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:padding="10dp" android:textSize="16sp" />
</LinearLayout>   

UPDATE: I now need to use an OnItemClickListener to pass the Package Name of the App selected to a method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:34:19+00:00Added an answer on May 22, 2026 at 3:34 am

    To display your activities’ names correctly in the list, you should override the getView method of your ListAdapter, and set some of your local variables as final (to work with inner class):

    @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<ResolveInfo> list =
                (ArrayList<ResolveInfo>) pm.queryIntentActivities(intent, 
                        PackageManager.PERMISSION_GRANTED);
        for (ResolveInfo rInfo : list)
        {
            Log.i(TAG, ": Installed Applications " + rInfo.activityInfo.
                    applicationInfo.loadLabel(pm).toString());
        }
    
        final ArrayAdapter<ResolveInfo> adapter = 
            new ArrayAdapter<ResolveInfo>(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);
    }
    

    This way you have your custom ArrayAdapter implementation, which displays the proper label of applicationinfo in the TextView.

    You can also achieve this, if you create a new ArrayList<String>, and populate it inside the for cycle where you log the applications:

    final ArrayList<String> labelList = new ArrayList<String>();
    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<String> adapter = new ArrayAdapter<String>(this, 
            R.layout.list_item, labelList);
    setListAdapter(adapter);
    

    Then you use this new labelList as the source of your adapter.

    Update
    To include the icon into the item renderers, the overridden getView method would look like:

    @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;
    }
    

    and your res/layout/list_item.xml layout file has to contain the text TextView and the image ImageView:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ImageView android:id="@+id/image" 
            android:layout_width="50dp" android:layout_height="50dp" />
        <TextView android:id="@+id/text"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:padding="10dp" android:textSize="16sp" />
    </LinearLayout>   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to write a very simple app that sends an object
I'm trying to write a very simple terminal app that will scan for Bluetooth
I'm trying to write a very simple app that will do just one very
I'm trying to write a very simple JMS app to deploy on Glassfish as
I'm trying to write a very simple Python utility for personal use that counts
I am trying to write a very simple Android application that checks the signal
I'm trying to write a very simple plugin that on anchor mouseover increases the
I'm trying to write a very simple program in C++ that finds the modulus
I am trying to write a very simple slide up and slide function that
I'm trying to write a very simple app for Android. It should do 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.