How to use Android Spinner like a drop-down list

后端 未结 6 1255
一个人的身影
一个人的身影 2020-12-05 14:22

It\'s taken me quite a while to get my head around the Android Spinner. After several failed implementation attempts, and after reading many questions partially similar to m

6条回答
  •  一整个雨季
    2020-12-05 15:06

    +1 to David's answer. However, here's an implementation suggestion that does not involve copy-pasting code from the source (which, by the way, looks exactly the same as David posted in 2.3 as well):

    @Override
    void setSelectionInt(int position, boolean animate) {
        mOldSelectedPosition = INVALID_POSITION;
        super.setSelectionInt(position, animate);
    }
    

    This way you'll trick the parent method into thinking it's a new position every time.

    Alternatively, you could try setting the position to invalid when the spinner is clicked and setting it back in onNothingSelected. This is not as nice, because the user will not see what item is selected while the dialog is up.

提交回复
热议问题