Possible Duplicate:
Getti开发者_JS百科ng values from the spinner inside the list
I've create the android application.. I have the list inside that, spinner is display based on the arraylist.. But the spinner is empty. how can i get the value of the spinner.If possible means tell some idea. Thanks in Advance..
Did you call this?
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
where adapter is an ArrayAdapter
?
Uthra you need to replace this code
final Spinner spinnertwo= (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adaptertwo = new ArrayAdapter<String> (this,android.R.layout.simple_spinner_item,mspinner);
spinnertwo.setAdapter(adaptertwo);
with this
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.planets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
You can create an array list like this inside strings.xml file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="planet_prompt">Choose a planet</string>
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
<item>Jupiter</item>
<item>Saturn</item>
<item>Uranus</item>
<item>Neptune</item>
</string-array>
</resources>
As @svidnas mentioned, use the link for more info
精彩评论