开发者

how to use Android Spinner with text and value?

i want to use Android spinner with following data. Spinner will display only text data not code.

code , text

1 , a
2, b
3,c
开发者_StackOverflow中文版

. . . etc

i have stored above comma seperated data in same activity class (Hard coded form) now if user selects "a" from the dropdown then it should get its code rather then text.

can any one guide me how to achieve this?

any help would be appriciated.


static final String[] LANGUAGE = new String[]
     {
        "English","Urdu","French","Spanish"

     };

Spinner ddltimezone=(Spinner)findViewById(R.id.ddlTimeZone);

 ArrayAdapter<String> adapter_time = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,TIME_ZONE); 
             adapter_time.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
             ddltimezone.setAdapter(adapter_time);


int indexlanguage = ddllanguage.getSelectedItemPosition() + 1;

and thats it. we have property of getting selecteditem position which sovled my problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜