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

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

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

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

IAR STM8 #pragma optimize 指令

IAR STM8 #pragma optimize 指令

参考资料:http://blog.csdn.net/niepangu/article/details/38066319 #pragma optimize= none  //one of none, low, medium, high, size, or speed放在被优化函数前 ...

XCode 模拟器完整分辨率截屏

XCode 模拟器完整分辨率截屏

选中模拟器 window-->去掉Show Device Bezels的勾选 -->Zoom 然后cmd + s 保存...

Word批量删除图片、超链接、空格等技巧

Word中的很多批量处理,实际上多是通过查找、替换功能实现的。而要调出“查找和替换面板”很简单,在“工具”菜单中选择“替换”或者按ctrl+H快捷键即可。下文中提到的“查找”或“替换&rdqu...

IIS+PHP环境下文件上传没法访问问题

PHP运行环境:IIS FastCGI 在IIS FastCGI方式运行时,经过浏览器请求的Web资源有2类,一个是经由php_cgi.exe产生的内容,一部分是静态资源,由IIS返回给用户。 这2类用户有区别,前者是IIS_IUSERS,后者是Authenticated User或者是Anonym...

穆斯林祈祷时间定义

穆斯林每天祈祷五次,时间有规定,需要在一个特定的时间段。五次祈祷分别是:晨礼、晌礼、晡(bū)礼、昏礼和宵礼。如下表所示: 名 称...

Win7 64bit右键添加 显示/隐藏文件+扩展名 及问题解决

目前网上广为流传的 显示/隐藏文件+扩展名有两种方式: 1、小工具 2、修改注册表 第一种方式,找个小工具软件,我找了很多,但都不适合Win7 64bit,XP或Win7 32bit或许适用。关于这个工具的相关介绍及下载,可以参照以下网址: http://www.iplaysof...

发表评论

访客

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