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

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

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

参考资料: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嵌套问题)” 的相关文章

C#将图片白色背景设置为透明

红色部分是关键 Image image = System.Drawing.Image.FromFile(@"C:\A.JPG"); Bitmap pbitmap = new Bitmap(image); pbitmap.MakeTransparent(Color.White);...

Project Serve 2010 Error:Project Server 2010 要求至少使用 Microsoft Internet Explorer 7

Project Serve 2010 Error:Project Server 2010 要求至少使用 Microsoft Internet Explorer 7

安装好project server2010后,提示: Project Server 2010 要求至少使用 Microsoft Internet Explorer 7.0。 如下图所示: 换成IE11,还是提示这个问题,怎么办呢?猜测可能是IE兼容性问题,于是修改兼容性设置 修改完后,问题又来了...

金蝶K3设置套打ActiveX 部件不能创建对象

金蝶K3设置套打ActiveX 部件不能创建对象

处理方式: 打开CMD命令提示符,执行以下命令注册加载该程序集即可解决。 C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe "C:\Program Files (x86)\Kingdee\K3ERP\K3Exc...

C# XmlSerializer无法创建文件或目录

C# XmlSerializer无法创建文件或目录

现象: 在某一台XP机器上,时而正常,时而弹出无法创建文件或目录 错误具体信息: 在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 在 System.IO.FileStream.Init(String path...

再谈无线网络受限——无法获得IP地址

前面曾经写了一篇[无线网络连接受限]的解决办法(http://xjtudll.cn/Exp/66/),本次再谈一些这方面的内容。上次无线网络受限导致的结果就是:无线网卡无法获得IP地址,即便信号很好,也一直连不上。上次最后的解决办法是用WEP加密方式,后来在网上看到WPA2-PSK加密方式更为安全,...

金蝶K3老单插件开发-如何刷新单据、锁定单据

在金蝶K3工业老单插件开发中,用SQL在后台更新了单据数据,如何刷新单据,将新的值显示在单据上?用 m_BillTransfer.DoRefreshControl方法是不行的,需要使用如下方法: m_BillTransfer.BillFunc.ReFillBill 再介绍几个K3工业老单BillFu...

发表评论

访客

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