0
 final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    final List pkgAppsList = this.getPackageManager().queryIntentActivities( mainIntent, 0);
    final String[] apps = (String[]) pkgAppsList.toArray();
    Spinner appSpinner = (Spinner) findViewById(R.id.spinner1);
    ArrayAdapter<CharSequence> appAdapter = new ArrayAdapter(this, apps, android.R.layout.simple_spinner_item);
    appAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    appSpinner.setAdapter(cloudAdapter);

The previous code is throwing out errors for me in eclipse. I understand how to get the list of installed apps, and I understand how to populate a spinner using the createFromResource method. However I've never attempted to do so in this manner? Anyone able to direct me in the right direction?

Stev0
  • 605
  • 11
  • 28

3 Answers3

0

Eventough it is late, you should use this constructor of ArrayAdapter instead :

ArrayAdapter<String> appAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, apps);
appAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
appSpinner.setAdapter(appAdapter);
Anonymous
  • 2,022
  • 14
  • 23
Yahia
  • 687
  • 5
  • 21
0

Create a file named arrays.xml inside values folder.

Inside that give:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="array_name">
        <item>value1</item>
        <item>value2</item>
    </string-array>
</resources>

Then inside your spinner,give:

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.array_name, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
spinner.setAdapter(adapter);

Hope this may work for you.

Anju
  • 8,924
  • 14
  • 50
  • 86
  • I am aware of how to do this. I'm trying to populate the spinner with an array created programmatically from the list of installed apps.... – Stev0 Mar 17 '11 at 07:21
0

Check : How to get a list of installed android applications and pick one to run

Community
  • 1
  • 1
Karan
  • 12,434
  • 6
  • 37
  • 33