本文介绍了与片段处理方向更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我目前正在测试我有multipane 片段使用HC兼容包-ised视图的应用程序,并且有很多的困难处理的方向变化。

I'm currently testing my app with a multipane Fragment-ised view using the HC compatibility package, and having a lot of difficultly handling orientation changes.

我的主机的活动有2个窗格景观(menu​​Frame 和 contentFrame C $ C>),只有 menuFrame 的肖像,到适当的片段被加载。如果我有东西两个窗格,但随后改变方向为纵向,我收到了NPE,因为它试图加载意见的片段,将在(不存在) contentFrame 。在内容片段使用 setRetainState()方法不起作用。我如何排序了这一点,以prevent系统加载,将不会显示一个片段?

My Host activity has 2 panes in landscape (menuFrame and contentFrame), and only menuFrame in portrait, to which appropriate fragments are loaded. If I have something in both panes, but then change the orientation to portrait I get a NPE as it tries to load views in the fragment which would be in the (non-existent) contentFrame. Using the setRetainState() method in the content fragment didn't work. How can I sort this out to prevent the system loading a fragment that won't be shown?

非常感谢!

推荐答案

看来, onCreateViewMethod 是造成问题;它必须返回null如果容器是空:

It seems that the onCreateViewMethod was causing issues; it must return null if the container is null:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    if (container == null) // must put this in
        return null;
    return inflater.inflate(R.layout.<layout>, container, false);
}

这篇关于与片段处理方向更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:14