简体   繁体   中英

ViewPager findViewById is null after screen rotation in android

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

do this in onActivityCreate of the fragment

pager = (CustomViewPager) getActivity().findViewById(R.id.pager);
pager.setPagingEnabled(false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM