Convert data from a spinner to String

1

How can I convert the data from Spinner to String ?

Spinner cur = (Spinner) findViewById(R.id.spinnerp);
    
asked by Pablo Gonzalez 06.03.2017 в 15:51
source

2 answers

1

Try this:

  Spinner cur = (Spinner) findViewById(R.id.spinnerp);
  String text =  cur.getSelectedItem().toString();
    
answered by 06.03.2017 в 15:53
0

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);
      }
    
answered by 06.03.2017 в 17:52