Android – How to keep onItemSelected from firing off on a newly instantiated Spinner


I've thought of some less than elegant ways to solve this, but I know I must be missing something.

My onItemSelected fires off immediately without any interaction with the user, and this is undesired behavior. I wish for the UI to wait until the user selects something before it does anything.

I even tried setting up the listener in the onResume(), hoping that would help, but it doesn't.

How can I stop this from firing off before the user can touch the control?

public class CMSHome extends Activity { 

private Spinner spinner;

    public void onCreate(Bundle savedInstanceState) {

    // Heres my spinner ///////////////////////////////////////////
    spinner = (Spinner) findViewById(;
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            this, R.array.pm_list, android.R.layout.simple_spinner_item);

public void onResume() {
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

    public class MyOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent,
        View view, int pos, long id) {

     Intent i = new Intent(CMSHome.this, ListProjects.class);
     i.putExtra("bEmpID", parent.getItemAtPosition(pos).toString());

        Toast.makeText(parent.getContext(), "The pm is " +
          parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();

    public void onNothingSelected(AdapterView parent) {
      // Do nothing.

Best Solution

The use of Runnables is completely incorrect.

Use setSelection(position, false); in the initial selection before setOnItemSelectedListener(listener)

This way you set your selection with no animation which causes the on item selected listener to be called. But the listener is null so nothing is run. Then your listener is assigned.

So follow this exact sequence:

Spinner s = (Spinner)Util.findViewById(view,,;
s.setSelection(position, false);
Related Question