在Android中旋转屏幕后,ViewPager findViewById为null [英] ViewPager findViewById is null after screen rotation in android
问题描述
我正在使用 viewPager
来显示一些表格.我的问题是,当我旋转设备的屏幕并再次创建 viewPager
时,当他到达 findViewById
viewPager >,始终为 null
.我不知道轮换时如何处理.我尝试了 onConfigurationChange
,但是它不起作用,我试图保存寻呼机的 Id
,然后使用保存的 id
进行检索,但是没什么所以我现在很受阻.
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);
在onViewCreated
In onViewCreated
推荐答案
在片段
pager = (CustomViewPager) getActivity().findViewById(R.id.pager);
pager.setPagingEnabled(false);
这篇关于在Android中旋转屏幕后,ViewPager findViewById为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!