How to select the previous selectedItem when Configurations changes?
I have a issue about spinner. I have many images in spinner when I select some image it shows the image and if I change the orientation like change to landscape its selected item list starts pointing the top开发者_开发问答 one in the list. How shall I prevent to do that?
Step #1: Override onRetainNonConfigurationInstance()
and, as part of whatever you return, include getSelectedItemPosition()
from the Spinner
.
Step #2: In onCreate()
, call getLastNonConfigurationInstance()
. If it is not null
, that is the object you returned in Step #1 above. Use the value from it to call setSelectedPosition()
on the Spinner
to set the selection to whatever it was before.
精彩评论