Why is onNothingSelected method needed in spinner listener?

后端 未结 2 1301
温柔的废话
温柔的废话 2020-12-16 10:21

native English speaker, so I\'d say sorry about my bad English skills to you guys.

I\'ve been studing Android since 5 weeks ago. I tried to implement a spinner and m

相关标签:
2条回答
  • 2020-12-16 10:58

    From the doc here.

    onNothingSelected is a Callback method to be invoked when the selection disappears from this view. The selection can disappear for instance when touch is activated or when the adapter becomes empty.

    I think it pretty much answers your question. So if your spinner disappear for other reason except selecting the item then onNothingSelected will be called. So as it's name tells it is needed to find out when nothing is selected

    0 讨论(0)
  • 2020-12-16 11:03

    As the documentation describes:

    Callback method to be invoked when the selection disappears from this view. The selection can disappear for instance when touch is activated or when the adapter becomes empty.

    This means that the method is called whenever the currently selected item is removed from the list of available items. As the doc describes, this can occur under different circumstances, but generally if the adapter is modified such that the currently selected item is no longer available then the method will be called.

    This method may be used so that you can set which item will be selected given that the previous item is no longer available. This is instead of letting the spinner automatically select the next item in the list.

    0 讨论(0)
提交回复
热议问题