ignore OnItemSelectedListener firing on create

后端 未结 5 1512
悲&欢浪女
悲&欢浪女 2021-02-19 06:48

I\'m creating a spinner and I\'ve added an OnItemSelectedListener to it. However I\'ve noticed that it fires on create. Now I was wondering if there wa

5条回答
  •  感情败类
    2021-02-19 07:20

    You should not attempt to prevent the call to the OnItemSelectedListener.

    By default, Android Spinners select the first item returned by the Adapter, and therefore the OnItemSelectedListener is called to trigger some action on that item.

    I would advise that the first item in your Spinner Adapter be a blank item, and your OnItemSelectedListener can ignore that blank item based on its id.

提交回复
热议问题