简体   繁体   English

在Android中旋转屏幕后,ViewPager findViewById为null

[英]ViewPager findViewById is null after screen rotation in android

I'm using a viewPager to display some forms. 我正在使用viewPager显示一些表格。 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 . 我的问题是,当我旋转设备的屏幕和viewPager创建再次,它没有看到viewPager当他到达findViewById ,它总是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. 我尝试了onConfigurationChange但是它不起作用,我试图保存寻呼机的Id ,然后使用该保存的id检索它,但是也什么也没有。 So I'm quite blocked now. 所以我现在很受阻。

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

In onViewCreated 在onViewCreated

do this in onActivityCreate of the fragment fragment onActivityCreate中执行此操作

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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