Android NullPointerException - Spinner onItemSelected `view` parameter is null after rotating

前端 未结 2 673
孤独总比滥情好
孤独总比滥情好 2020-12-18 03:50

Note: A limiting workaround from another, similar SO question\'s answer worked for me, but I am interested in finding a true solution. The workaround was to

2条回答
  •  天涯浪人
    2020-12-18 04:00

    public void onItemSelected(AdapterView parent, View view, int position, long id)
    

    adapterView is referenced to Spinner, not the item you clicked, you should cast the "view" parameter instead.


    @Rock Lee After rotated the layout would be refresh, you should resetup the spinner in some callback function like onConfigurationChanged(Configuration newConfig), Android listview disappears after screen rotation

提交回复
热议问题