java视图没了怎么办_java – 没有视图的片段在配置更改时崩溃

我有一个UI,我需要一个片段,以横向模式显示(视图),但不是在纵向模式。在纵向模式下,它仍然可用,但会使用L​​istPopupWindow显示其结果。

我想我可以通过使用< fragment />标记为横向布局,同时以编程方式创建片段(如果未开始)(在我们是纵向的情况下)。

只要您从横向开始,只要您从头开始,以编程方式创建片段,当您尝试将该片段附加到布局时旋转仿真器时,应用程序将崩溃:

java.lang.IllegalStateException:

Fragment did not create a view.

at

android.app.Activity.onCreateView(Activity.java:4095)

Fragment.isInLayout()的文档似乎暗示它应该能够这样处理:

Return true if the layout is included

as part of an activity view hierarchy

via the tag. This will

always be true when fragments are

created through the tag,

except in the case where an old

fragment is restored from a previous

state and it does not appear in the

layout of the current state.

所以问题是如何正确地做到这一点,还是有缺点的东西?

更新:

像isInLayout()似乎不像现在那样行事。如果您已经手动将容器添加到容器中,则返回false。

另外,如果您将片段手动添加到容器中,然后将(设备)旋转到不包含该布局的布局,则它将崩溃:

Caused by:

java.lang.IllegalArgumentException: No

view found for id 0x7f060011 for

fragment SearchFragment{4042f868 #2

id=0x7f060011 SearchFragment} at

android.app.FragmentManagerImpl.moveToState(FragmentManager.java:722)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值