开发者

Spinner data to string

I have a spinner bounded with data, and I want to se开发者_开发百科lect it and put the string selected in a variable..

How can I do this?


You can use getSelectedItem to get the currently selected item. If you've bound to an ArrayAdapter<String>, this will be the value.

Hope this helps,

Phil Lello


Assuming the data is a plain String,

  mySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
        String str = (String) parent.getItemAtPosition (pos); // Your string
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {
        // your code here, if any 
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜