Here you can find the source of getIndex(Spinner spinner, long itemID)
@SuppressWarnings("resource") public static int getIndex(Spinner spinner, long itemID)
//package com.java2s; import android.database.Cursor; import android.widget.Spinner; public class Main { @SuppressWarnings("resource") public static int getIndex(Spinner spinner, long itemID) { Cursor spinnerItem = null; long spinnerItemID = -1; int spinnerIndex = -1; for (int i = 0; i < spinner.getCount(); i++) { spinnerItem = (Cursor) spinner.getItemAtPosition(i); spinnerItemID = spinnerItem.getLong(spinnerItem .getColumnIndexOrThrow("_id")); if (spinnerItemID == itemID) { spinnerIndex = i;/*w ww . jav a2 s .c om*/ break; } } // Cannot close the spinnerItem // It is used in the spinnter /*if (spinnerItem != null) { spinnerItem.close(); }*/ return spinnerIndex; } }