roomorama / Caldroid

A better calendar for Android
Other
1.42k stars 531 forks source link

orientation change issue #340

Open roygwsidev opened 8 years ago

roygwsidev commented 8 years ago

using Calendar in fragment calendar hide on orientation change screenshot_1

thomasdao commented 8 years ago

you should create new caldroidfragment and replace it instead of reusing the same instance

roygwsidev commented 8 years ago

Hi thomasdao, thanks for answer but issue is that i'm using it inside ViewPager and returning static instance of fragment

thomasdao commented 8 years ago

@roygwsidev when orientation changes, you can still create new instance of CaldroidFragment and update your static variable to point to this new instance

roygwsidev commented 8 years ago

@thomasdao FragmentPagerAdapter's override getItem() call once when activity create. it keeps all attached fragments instance with it. the getItem(int) wasn't called anymore for that fragment.

thomasdao commented 8 years ago

@roygwsidev I don't have a very optimized answer for your setup yet, but the easiest solution is to re-create your viewpager, so getItem will be called again. I'm not sure if it affect your app performance, you should test and see how it works

hagabaka commented 8 years ago

I posted the following comment in the closed #242, before finding this issue. It would be really helpful to find a way to solve this problem other than recreating caldroid:

I have a similar problem although my setup is somewhat different. I wanted caldroid to use a custom style in portrait only, with reduced cell padding. I implemented it by placing the caldroid fragment inside the layout XMLs, where the portrait layout contains my subclass caldroid fragment using the custom style. This means I can't use setArguments since "fragment is already active", so I just set parameters using the available set methods.

Caldroid itself is contained in another fragment which is contained in an activity. I used to recreate caldroid's parent fragment on screen rotation, and this setup worked. But now I'm trying to preserve the parent fragment's state using FragmentManager.{put,get}Fragment, and after the fragment is restored, caldroid will have blank contents except the month header bar.

Is there a way to fix this problem without recreating a caldroid fragment instance?

Lex74 commented 8 years ago

I have the same issue as roygwsidev has. Maybe we need to extend CaldroidFragment and override something?