开发者

How to select the previous selectedItem when Configurations changes?

开发者 https://www.devze.com 2023-01-19 19:27 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消