0

I'm using the spinner, and I want to get the text selected for the user so I'm using

String datacat = categorySpinner.getSelectedItem().toString()

the problem is that this sentence also return the tag of the spinner in a String like this: {supplier=VITA}, but I need to get only the VITA value

Keith Pinson
  • 7,835
  • 7
  • 61
  • 104
Pedro Teran
  • 1,200
  • 3
  • 17
  • 43

2 Answers2

1

Assuming selectedview is EditText.

String datacat =((EditText) categorySpinner.getSelectedView()).getText().toString();
kosa
  • 65,990
  • 13
  • 130
  • 167
  • getText is nos a valid method for getSelectedView or getSelectedItem – Pedro Teran Mar 01 '12 at 21:39
  • see my updated answer. Again, assuming your view is EditText, otherwise you will get ClassCastException. – kosa Mar 01 '12 at 21:45
  • is a spinner not a EditText I got the ClassCastException I'm trying to get the text of the item selected on the spinner view – Pedro Teran Mar 01 '12 at 22:07
  • Spinner is not edittext, spinner may have edittext. Did you try solution in this link http://stackoverflow.com/questions/2652414/how-do-you-get-the-selected-value-of-a-spinner-android – kosa Mar 01 '12 at 22:09
0

try

String datacat = categorySpinner.getSelectedView().getText().toString()

you may have to cast the view before you can call getText()

ByteMe
  • 1,436
  • 12
  • 15