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

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

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

参考资料: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://www.xjtudll.cn/Exp/368/

标签: Android
分享给朋友:

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

C# MDI 子窗体被父窗体控件挡住

C# MDI 子窗体被父窗体控件挡住

https://blog.csdn.net/chenyblog/article/details/40752029最近在做一个小工具,发现了一个过去做项目没有遇到的问题:子窗体被父窗体的控件给挡住了!如下图所示:子窗体的TopMost 已经设为true,父窗体的控件已经置于底层,但是结果还是很悲观!无...

DFC逻辑调频

DFC逻辑调频

2035机芯有个技术指标:DFC。如下图所示。 DFC,全称Digital Frequency Control,即逻辑调频。 我们知道,在所有的电子产品指标中,频率尤为重要,要想获得比较稳定的振荡,最广泛的就是使用石英振子,包括在手机和电脑里都有,石英手表更是如此,它用石英晶体的振荡来做时基,故...

ListView.setOnItemClickListener 点击无效

如果ListView中的单个Item的view中存在checkbox,button等view,会导致ListView.setOnItemClickListener无效, 事件会被子View捕获到,ListView无法捕获处理该事件. 解决方法: 在checkbox、button对应的view处加...

SQL Server配置网络路径

远程数据库服务器名:ChenCunServer @@servername:ChenCunServer 现在需要在此机上新建发布。在第三步中,指定快照文件夹。默认是:D:\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\ReplData...

Xcode Warning: Multiple build commands for output file /xxx 解决

Xcode Warning: Multiple build commands for output file /xxx 解决

 现象: 编译后有如下警告: [WARN]Warning: Multiple build commands for output file /xxx 解决步骤如下: 1、选择你的工程 2、选择target 3、点击 Build Phases 4、展开...

运放运用中容易忽视的问题

本文收集于网络,原文作者:djyos。 在嵌入式设计中,数字部分的功能越来越强大,而模拟电路大有被边沿化的趋势,但不管怎样,传感器以及其调理电路,还是离不开模拟电路的,其中运放是不可或缺的模拟器件。 本文谈谈在设计运放电路中容易被设计人员疏忽的问题,不注意这些问题,可能导致你的电路看起来能够工作...

发表评论

访客

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