4

I'm trying to create a Spinner with integers values (1, 5, 10, etc.) I already have a Spinner with Strings and everything is working fine.

private static final String[] daysOfWeek = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
Spinner spinner_days =(Spinner)findViewById(R.id.spinner_days);
spinner_days.setOnItemSelectedListener(this);

ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, daysOfWeek);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_days.setAdapter(aa);

When I'm trying to do the same thing with

private static final int[] options = {1, 3, 5, 10, 15, 20, 30, 40, 45, 50, 60};

then I get an error when I try to create the ArrayAdapter because I think it's only possible to do that with a String array ?

Can someone please help me?

Thank you!

2
  • All you have to do is format your integers into a string array. I do not see the problem. Commented Nov 14, 2012 at 17:58
  • because I need them to be integers, is it possible? Commented Nov 14, 2012 at 18:05

1 Answer 1

4

You cannot create an ArrayAdapter of ints, so you could either try making a string array with numbers in it instead. Try this -

public static final String [] options = {"1", "3", "5", "10", "15", "20", "30", "40", "50", "60"}

Or, you can do this using an Integer instead of an int

Integer[] options = new Integer[]{1, 3, 5, 10, 15, 20, 30, 40, 50, 60};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.