0

i have a personaliced spinner (that uses a adapter that uses a personalized xml layout file)

i want to pass him a array of strings, programatically created, instead of passing the tipical hard coded string array of strings.xml... but i can't!! if i try to pass a array of strings, eclipse tell me that he needs a reference of a item from resources (a hard coded string array from strings.xml)

also i tryed to use the answer of this another way: Android: Create spinner programmatically from array

but that way didn't work's for me, because that way must use the default layout android.R.layout.simple_spinner_item and i won't work with that layout, i need to use my personalized layout (R.layout.spinner_layout), and that method didn't let me to use personalized layouts for the spinner

this is my code:

String[] teams=(String[])Primera.getTeams().toArray();

ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.teams_array, R.layout.spinner_layout);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
TeamsSpinner.setAdapter(adapter);
TeamsSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

i need to changue R.array.teams_array, to teams, but i can't because the reason i told some lines up

can anyone help me ?

thanks

Community
  • 1
  • 1
NullPointerException
  • 36,107
  • 79
  • 222
  • 382

1 Answers1

2

You do not have to use the android.R.layout.spinner_item etc. like what is being used in the question you reference. You can use your own layout xml for the spinner item.

You do not have to use ArrayAdapter.createFromResource() you can use:

ArrayAdapter adapter = new ArrayAdapter(this, R.id.your_custom_spinner_item, teams);
citizen conn
  • 15,300
  • 3
  • 58
  • 80
  • ..... spinner_item is my own custom_spinner_item...... i told in the question. And also i tryed to do without createFromResource and it fails, i told also in the question..... plz read before answer :( – NullPointerException Jul 26 '11 at 07:30