what's different?
The first option creates an anonymous inner class that implements the interface. This is useful when you need multiple OnItemSelectedListener
implementations that differ significantly.
In the second option, your Activity implements OnItemSelectedListener
, so (assuming that you pass this
to each of your Spinners) every Spinner will go to the same OnItemSelectedListener
instance.
which is more standard written?
It depends on your personal preference and your use case.
If all of your Spinners have similar behavior or simple enough behavior that onItemSelected()
will be short, then the latter option would work fine.
However, if each of your Spinners is highly unique and share little common code in onItemSelected()
, then creating a new OnItemSelectedListener
instance for each Spinner might be a better design decision.