开发者

Using Gallery.setSelection(position) during onCreate

I'm creating an application that has a Gallery,开发者_C百科 and this Gallery has a different number of Views depending on orientation. Broadly, some wide images are double-page spreads; as such they take up one View in landscape, but they are split to two Views (one per page) in portrait.

I have a system that remembers which "page" is selected and converts this to a position that can be sent to Gallery.setSelection(position). I'm calling this from Activity.onCreate(), using Activity.onRetainNonConfigurationInstance() to pass the object holding this, among other, information back to the application. Unfortunately Gallery then seems to be resetting itself to its previous position value after onCreate finishes.

Can I suppress this? If not, when do I need to call my Gallery.setSelection(position) method?


I worked it out.

When the orientation changes, Activity.onCreate() is called and everything is inflated. By overriding Activity.onResume() and calling Gallery.setSelection(position) with the desired value after super.onResume(), it is possible to get the correct behaviour; presumably the Gallery's selection is set to its previous value either during super.onResume() or in between Activity.onCreate() and Activity.onResume().

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜