1

I am having an Android view with a Spinner on it. I call a populateSpinner() method to add some default values to it.

I also have a onItemSelected() event which gets called before the view is completed to print. I would like to run a code inside this block only when the user changes the selected items, not when I add or the form gets created.

How is possible that?

Pentium10
  • 204,586
  • 122
  • 423
  • 502

2 Answers2

2

Have you tried waiting until you have populated the Spinner to register the onItemSelectedListener?

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • 1
    By 'waiting until you have populated the Spinner', you mean setting the adapter for the spinner, right? I call 'setOnItemSelectedListener' only after I call 'setAdapter' method on the spinner, but still the 'onItemSelected' event gets fired at the initialization of the activity. – Samik R Aug 04 '10 at 05:59
2

Pentium10, I have found a solution for this problem and posted it here (with code sample):

Spinner onItemSelected() executes when it is not suppose to

Community
  • 1
  • 1
Someone Somewhere
  • 23,475
  • 11
  • 118
  • 166