0
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(RoutesActivity.this, directionArray, R.id.route_direction_spinner);

So, I'm trying to make a spinner, and I have a java String array (directionArray). My problem is Eclipse returns this error when hovering over "createFromResource": "The method createFromResource(Context, int, int) in the type ArrayAdapter is not applicable for the arguments (RoutesActivity, String[], int)" And gives me this Quick Fix: "Change type of 'directionArray' to 'int'." Basically, I have an array in Java that I need to use in an ArrayAdapter, but apparently it won't let me. Is there a way to create an xml resource from within java, and/or a way to bypass the above error?

2 Answers 2

2
ArrayAdapter<String> adapter = new ArrayAdapter<String>(RoutesActivity.this, android.R.layout.simple_spinner_item, directionArray);

Use this then your standard:

Spinner spinner1 = (Spinner) findViewById(R.id.route_direction_spinner);
spinner1.setAdapter(adapter);
Sign up to request clarification or add additional context in comments.

4 Comments

Tried what you said, didn't work, but it gave me the suggestion to change it to this: ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, directionArray); Seems to be working.
Ah, basically you weren't using a CharSequence but a String. I should've caught that, my bad. Still I'm glad I helped :)
Haha, learning experience for me though. I'd upvote but I cant yet :P
We were all there. In my case just started learning a few months ago from scratch. If it helps this is the tutorials I used to learn: youtube.com/course?list=EC2F07DBCDCC01493A - this guy is awesome.
0

No, XML resources are parsed into binary format at compile time. You cannot create new XML resources at runtime.

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.