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

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

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

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

Keil优化导致代码出错

Keil优化导致代码出错

Keil在优化代码的时候,对于一些隐式调用,会出错的。 例如(以下例子来源于参考资料): 你在ROM的0x00002000处定位了一个函数,假设为void test(void),然后使用函数指针来调用它: void (*UserProgram)();    &...

焊接的一些心得

这几天,不断的在焊接一些贴片元件,都是焊盘在IC底下,侧面看不到任何焊盘的IC,例如KXTE9,MMC2121。总结起来有以下几点要注意的地方 1、IC焊盘要与PCB上的焊盘对齐 这点实际上是说起来容易,做起来难。而实际上,只要焊盘对齐了,焊接就完成了80%。在实际操作中可以这样做 (1)画...

iOS10,Xcode8上传AppStore的时候,找不到构建版本

iOS10,Xcode8上传AppStore的时候,找不到构建版本

参考资料:http://blog.csdn.net/u013283787/article/details/52593143 使用Xcode8成功上传app之后,在itunes connect 构建版本里根本找不到上传的版本。 网上搜了搜,又查了一下邮件    &nb...

Windows10 安装软件时提示 the error code is 2503/2502 错误解决办法

Windows10 安装软件时提示 the error code is 2503/2502 错误解决办法

问题内容:Windows10 安装软件时提示“ the error code is 2503/2502”错误代码分析原因:由于安装.msi格式的软件时,无法使用管理员身份运行,导致权限不够,从而引起2503/2502代码的错误解决方法:设置 C:\WINDOWS\TEMP的权限1、依次打开“ 我的电...

找不到System.Web.dll

找不到System.Web.dll

  这个其实是编译配置选错了。Client Profile里不包含System.Web.dll,只有完整的.Net才有这个。...

如何获取.NET Framework目录路径?

问题: 如何在C#应用程序中获取.NET Framework目录路径? 例如:“C:\ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727” 方法: 通过使用以下方法可以获取当前.NET应用程序活动的CLR安装目录的路径: Sys...

发表评论

访客

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