Java Review
Java Review

Reputation: 427

I need help with my first Spinner!! Not Displaying values

This is the first time I am trying to use a spinner and I need some help.. I made a layout with a spinner object on it and then I also made a array.xml with the numbers that I would like in the spinner in it. I run the following code and the screen displays without any values in my spinner??

public class SpinnerExaple extends Activity {
    private Spinner numbersSpinner;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        this.numbersSpinner = (Spinner) findViewById(R.id.Spinner01);

        ArrayAdapter<String> numbersArray =
            new ArrayAdapter<String>(this, R.layout.main,
            getResources().
            getStringArray(R.array.numbers));
        }
}

Upvotes: 1

Views: 109

Answers (2)

dogbane
dogbane

Reputation: 274592

You never set your numbers array into the spinner. Try adding the following at the end of the method:

numbersSpinner.setAdapter(numbersArray);

Also check out the hello-spinner tutorial.

Upvotes: 1

Jems
Jems

Reputation: 11620

You got the reference to the spinner, you got your AdapterArray set correctly- but you didn't attach the adapter to your spinner.

Add the line:

numbersSpinner.setAdapter( numbersArray );

Upvotes: 2

Related Questions