How can I convert the data from Spinner
to String
?
Spinner cur = (Spinner) findViewById(R.id.spinnerp);
How can I convert the data from Spinner
to String
?
Spinner cur = (Spinner) findViewById(R.id.spinnerp);
Try this:
Spinner cur = (Spinner) findViewById(R.id.spinnerp);
String text = cur.getSelectedItem().toString();
To obtain the selected data within Spinner
:
Spinner cur = (Spinner) findViewById(R.id.spinnerp);
String textoElementoSeleccionado = cur.getSelectedItem().toString();
or
String textoElementoSeleccionado = (String)cur.getSelectedItem();
To get all the elements of a Spinner
:
List<String> textosSpinner = new ArrayList<String>();
for (int i = 0; i < listViewDatos.getChildCount(); i++) {
View listItem = listViewDatos.getChildAt(i);
Spinner cur = (Spinner) listItem.findViewById(R.id.spinnerp);
//Obtiene texto.
String selection = cur.getSelectedItem().toString();
//agrega textos a List.
textosSpinner.add(selection);
}