Android Spinner.setSelection() doesn't work

后端 未结 2 1496

I\'m having a spinner which is populated with a CursorAdapter. Now when creating that spinner (dynamically) I want to set a default selection different to 0 (0

相关标签:
2条回答
  • 2021-01-11 13:24

    Try Spinner#setSelection (int position, boolean animate) with animate = false. I remember a while back I had a similar problem and this did the trick. The internal implementation seems to differ apart from the difference coming from the animate part.

    0 讨论(0)
  • 2021-01-11 13:47

    If you know default selected spinner item, it can be written as follows:

    Spinner sp = (Spinner) findViewById(R.id.spinner);
    sp.setSelection(0);   // sets the first item 
    

    onItemselectedlistener is called when you change the spinner item selection.

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