问题
I'm using a viewPager
to display some forms. My problem is when i rotate the screen of the device and the viewPager
is created again, it doesn't see the viewPager
when he reaches the findViewById
, it's always null
. I have no idea how to handle it when rotation change.
I tried the onConfigurationChange
but it doesn't work, I tried to save the Id
of the pager and then retrieve it using that saved id
but nothing too. So I'm quite blocked now.
pager = (CustomViewPager) getActivity().findViewById(R.id.pager);
pager.setPagingEnabled(false);
In onViewCreated
回答1:
do this in onActivityCreate
of the fragment
pager = (CustomViewPager) getActivity().findViewById(R.id.pager);
pager.setPagingEnabled(false);
来源:https://stackoverflow.com/questions/21699006/viewpager-findviewbyid-is-null-after-screen-rotation-in-android