当前位置:首页 > 技术心得 > 正文内容

Android error:Duplicate ID, tag null, or parent id with another fragment(fragment嵌套问题)

xjtudll11年前 (2015-10-11)技术心得12650

参考资料:http://stackoverflow.com/questions/14083950/duplicate-id-tag-null-or-parent-id-with-another-fragment-for-com-google-androi


跟参考资料里的这个人一样,我也碰到了这个问题,原因也与其类似。
我有个Activity,里面有个fragment,而这个fragment对应的xml文件里,又加载了其他fragment。
这是xml的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button_find"
android:layout_gravity="center_horizontal"
android:background="@drawable/find_button_selector"
android:layout_marginBottom="15dip"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="10dip" />

<fragment
android:layout_width="wrap_content"
android:layout_height="0dp"
android:name="com.xonix.notifyWatch.ui.FragmentAlertSetting"
android:id="@+id/fragment_alert"
android:layout_weight="1"
tools:layout="@layout/setting" />

</LinearLayout>
</LinearLayout>

很明显,是属于fragment嵌套。
使用参考资料的方法,先判断view是否存在,不存在则加载xml。
private static View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (view != null) {
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null)
parent.removeView(view);
}
try {
view = inflater.inflate(R.layout.find, container, false);
} catch (InflateException e) {
       }
return view;
}
 


扫描二维码推送至手机访问。

版权声明:本文由鸟的天空发布,如需转载请注明出处。

本文链接:http://xjtudll.cn/Exp/368/

标签: Android
分享给朋友:

“Android error:Duplicate ID, tag null, or parent id with another fragment(fragment嵌套问题)” 的相关文章

CC2541功耗测试结果

CC2541功耗测试结果

测试环境: 1、CC2541开发板 2、使用heartrate工程,修改心率发送间隔时间为1秒(原来是2秒) 测试结果: 慢速广播 10 uA 快速广播 2 mA 仅定时器运行:1.2 uA(蓝牙关闭) 休眠:0.34 uA 与手机连接时刻:1 mA 约持续10秒 保持连接状态(1秒发送一次心率值...

Windows Live Writer:Object moved问题解决

用Windows Live Writer已经有很长时间了,可以方便的从Word里面拷贝文章,再也不用理会博客后台那蜗牛般的速度了。这就是Windows Live Writer强大的地方。 今天用Windows Live Writer更新博客时,突然提示: Found: Object moved...

IIS WCF 调用COM问题

IIS WCF 调用COM问题

参考资料: http://cn.voidcc.com/question/p-msefzjic-so.html https://www.cnblogs.com/CrazyKey/archive/2012/07/13/2590083.html https://www.cnblogs.com/Lulus/...

Android Studio升级至3.1出现AAPT2 error的解决办法

Android Studio升级至3.1出现AAPT2 error的解决办法

android studio从2.3升级到3.1.3之后,编译提示:AAPT2 error: check logs for details 网上的方法一堆,但几乎都没啥用。以下部分内容引用简书: https://www.jianshu.com/p/2a63c5710ee9 1:Android Stu...

Xcode查找函数(方法)调用及被调用

Xcode查找函数(方法)调用及被调用

参考资料:http://stackoverflow.com/questions/7145045/find-method-references-in-xcode 这个功能有的说是 Find Caller,有的说是Find references,有的说是Find Usages 直白的讲,就是我需要知道这...

android Service : onStartCommand intent为null

参考资料: http://hold-on.iteye.com/blog/2024926 问题: service中加入onStartCommand之后,不定期crash。 分析: 经查看onStartCommand中代码,只有intent为空才可能报NullPointException 。 inten...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。