Android: setSelection having no effect on Spinner

前端 未结 11 1308
我在风中等你
我在风中等你 2020-11-27 05:24

I\'m having some problem with setSelection on a Spinner. I set the value to be pre-selected when the spinner is shown in code, but it has no effect and the first alternative

11条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 05:41

    None of the previous answers worked for me. What did work, though, was creating the instance variable mSpinner in the onCreateView() method of my fragment (or in the onCreate() method of your activity), then doing this in my onLoadFinished() method...

    @Override
    public void onLoadFinished(Loader loader, Cursor cursor) {
        adapter.swapCursor(cursor);
        //mSpinner.setAdapter(adapter);
        mSpinner.setSelection(mSelectedIndex);
    }
    

提交回复
热议问题