开发者

How to use the spinner inside the list that extends listactivity [duplicate]

This question already has answers here: Closed 11 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜