views:

1043

answers:

2

Hi,

I'm all new to Android and I'm trying to create a spinner programmatically and feeding it with data from an array, but Eclipse gives me a warning that I can't handle.

Here's what I got:

This ArrayList holds the elements that should be in the spinner (gets filled from a file later on):

ArrayList<String> spinnerArray = new ArrayList<String>();

This is code I found on a site which should create the spinner:

    Spinner spinner = new Spinner(this);
    ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this,
        android.R.layout.simple_spinner_dropdown_item,
            spinnerArray);
    spinner.setAdapter(spinnerArrayAdapter);

Now the second line (ArrayAdapter...) gives me a warning in Eclipse saying "ArrayAdapter is a raw type... References to generic type ArrayAdapter<T> should be parameterized", I have no idea how to fix this (or what that means in the first place :) ).

It's just a warning and the App seems to run alright, but I'd still like to understand what's wrong and fix it. Any hint is appreciated.

Greetings, Select0r

+1  A: 
ArrayAdapter<String> should work.

i.e.:

Spinner spinner = new Spinner(this);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
spinner.setAdapter(spinnerArrayAdapter);
Brandon
I tried that but the error just changes slightly :)`Type safety: The expression of type ArrayAdapter needs unchecked conversion to conform to ArrayAdapter<String>`
Select0r
Commented to quickly while you edited your post :) I missed the second `<String>`, your code works now, thanks a lot!
Select0r
A: 

This actually worked for me

    Spinner spinner = new Spinner(this);
    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
            this, android.R.layout.simple_spinner_item, spinnerArray);
    spinnerArrayAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );

    spinner = (Spinner) findViewById( R.id.spinner );
    spinner.setAdapter(spinnerArrayAdapter);
Opy