Android Spinner.setSelection() doesn't work

后端 未结 2 1503

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: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.

提交回复
热议问题