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
}
}
精彩评论