tags:

views:

169

answers:

2

Hi!

I need to get an item's position in spinner knowing it's ID. I've tried to do it with Spinner and SpinnerAdapter classes but there are no corresponding methods there.

Thanks,

Aleksander

+1  A: 

You create the Spinner items via your SpinnerAdapter, so you determine the position of the items. If you create the Spiner items from some kind of collection, you could search that for the ID.

molnarm
And what's for content provider as a data source for my adapter? ;)
Aleksander O
+1  A: 

you can query the selected position by Spinner.getSelectedItemPosition()

or alternatively you will get the selected item position if you override the method onItemSelected()

Vamsi
The matter is I need to SET selected item knowing item's ID. There's no such method as setSelectedItem(long id) so I need a position
Aleksander O
well if you are using an array adapter you know how many elements that you are going to insert, in that case you can set by calling Spinner.setselection(int position) position refers to the element in the Listadapter starting from 0.
Vamsi