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

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

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

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

mircrosoft project2010怎么设置任务级别,降级

mircrosoft project2010怎么设置任务级别,降级

参考资料: http://zhidao.baidu.com/link?url=hW3eTVmKLi2WzQM_jTfsCb2btmRnrmixR8tfFfiRn1YTtM6ylBBXMsnQHpEAUefawNdg-bTiFeXh9Of-U47Mma 两个方法: 1、任务菜单---计划列表---那两...

Android x86 4.4 RC2卡在跳过Wifi后面一步

Android x86 4.4 RC2卡在跳过Wifi后面一步

问题:Android x86 4.4 RC2卡在跳过Wifi后面一步,没法跳过,一直死循环。 无论怎么改都在这步了, 返回了也不知道从哪可以跳过。   解决办法: 一、在语言选择界面用鼠标在 左上-右上-右下-左下 四个角各点一遍 这个方法不知道是谁试出来的,这么扯蛋的办法都能想到。 二...

OKI单片机-如何查看编译后程序占用的RAM和ROM大小

OKI单片机-如何查看编译后程序占用的RAM和ROM大小

OKI单片机程序编译成功后,Project目录下将会多出一个map文件。通过这个文件,可以知道程序占用的RAM和ROM 1、程序占用ROM 分两种情况,第一种情况如下图: 像这种情况,占用ROM是: Total size(CODE) + Total size(TABLE) = 1916+95 =...

Coreldraw批量导出图片

Coreldraw批量导出图片

问题: 多个Coreldraw(cdr)文件,需要导出jpg或png图片文件,但不想通过打开每个文件来导出。如何批量导出jpg或png图片文件?   解决办法: 网上有人说,采用宏的方式,但这个需要自己编写宏,对菜鸟来说太难;还有人说,给Coreldraw安装一个插件,但根本不知道用什么插...

CrystalDecisions.Windows.Forms.CrystalReportViewer.DisplayGroupTree”已过时

问题:早期工程升级到VS2010 提示: CrystalDecisions.Windows.Forms.CrystalReportViewer.DisplayGroupTree”已过时 解决办法: this.crystalReportViewer1.DisplayGroupTree =...

vs2012 与 win7 不兼容的问题

vs2012 与 win7 不兼容的问题

问题描述:安装VS2012后,打开提示与此版本的 Windows 不兼容 如下图: 一开始以为是VS2010不能安装在Win7 64bit上,后来发现有个补丁,安装好之后,就能使用了。 Update for Microsoft Visual Studio 2012 (KB2781514) http...

发表评论

访客

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