安卓&碎片
简而言之:我将向您展示我的问题的抽象版本,所以我有: - 1 个 Activity,1 个 main.xml,其中 1 个 FrameLayout 作为容器(ID = main_container) - 片段A,B(A有点复杂)
我可以在main_container中插入任何片段A或B,没有任何问题。我还可以做一些片段替换B,A,B,A(当我进行最后一次交换时它失败了!)或A,B,A(在最后一个交换时再次失败)
为了让你了解我的android技能,我总是这样做:
FragmentX newX = FragmentX.newInstance(..);
FragmentTransaction ft ..
ft.replace(R.id.main_container, newX);
//ft.addToBackStack(null);
ft.commit();
所以我收到的错误:
"E/AndroidRuntime(2559): android.view.InflateException: Binary XML file line #7: Error inflating class fragment
...
E/AndroidRuntime(2559): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:664)"
这种方法有问题吗?您是否需要回收片段,因为如您所见,我总是使用 newInstance() 静态方法?或者您认为问题出在其他地方?
====更新==== 原来我的情况是这样的: 片段A(复杂的:))膨胀了一个fragment_A.xml,它有2个片段标签,为此我确实定义了2个片段类。
无论如何,我做了修改,从fragment_A.xml中删除2个片段标签并使用2包含标签..并且只使用一个大片段类:(。
现在它工作得很好,但在我看来,以前的形式应该已经工作了。
To cut is short: I will present you a abstract version of my problem, so I have:
- 1 Activity, 1 main.xml with 1 FrameLayout as a container (ID = main_container)
- Fragment A, B (A is a bit more complex)
I can insert any fragment A or B in main_container, without any problems. I also can do some fragment replacing B,A,B,A (when I do the last swap it fails!) or A,B,A (again it fails at the last one)
To give you a idea of my android skills, I always do:
FragmentX newX = FragmentX.newInstance(..);
FragmentTransaction ft ..
ft.replace(R.id.main_container, newX);
//ft.addToBackStack(null);
ft.commit();
So the error I receive:
"E/AndroidRuntime(2559): android.view.InflateException: Binary XML file line #7: Error inflating class fragment
...
E/AndroidRuntime(2559): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:664)"
Is there something wrong with this aproach? Do you need to recycle fragments, because as you see I always use the newInstance() static method? Or do you think the problem is elsewhere?
==== UPDATE ====
It turns out that my situation was like this:
fragment A (the complex one :)) inflated a fragment_A.xml which had inside 2 fragment tags, for which I did had 2 Fragment classes defined..
Anyways I made the modication of removing the 2 fragment tags from fragment_A.xml and using 2 include tags..and using just one big fragment class :(.
And now it works just fine, but in my mind previous form shoud have worked to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论