Question: 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

Answer: 
Try this:

```
static final int getAdapterPositionById(final Adapter adapter, final long id) throws NoSuchElementException {
    final int count = adapter.getCount();

    for (int pos = 0; pos < count; pos++) {
        if (id == adapter.getItemId(pos)) {
            return pos;
        }    
    }

    throw new NoSuchElementException();
}

```

It's generic enough to work for any adapter type that supports ids (e.g., implements `Adapter#getItemId(int position)` in a **meaningful** way)
you can query the selected position by `Spinner.getSelectedItemPosition()`

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