Android XML Parser - Creating Spinner

2019-02-27 14:25发布

问题:

Hi i am parsing xml file to insert buttons,textview and for creating them i am calling a function for each so that it may create many, depending on the xml. Now, i like to create a spinner in that xml. But i want to insert its items from an array.

<item>
<id>1</id>
<text>text1</text>
</item>
</items>

i dont want to enter the text in this way. i want to call an array.So what do i need to do? how i am going to record array name into xml and call it? Can somebody please help me ?

回答1:

Did you try to set Adapter on that spinner ? Like this :

Spinner spinner = ...;
final String[] choices = {"1","2"};

ArrayAdapter<String> adapter =new ArrayAdapter<String>(ObservationSubmit.this,android.R.layout.simple_spinner_item, choices);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

spinner.setAdapter(a);