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

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

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

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

找回丢失的“显示桌面”图标

Windows快速启动栏里面有个“显示桌面”的图标,点击图标就能快速切换到桌面,这个用起来很方便,当然用Windows+D快捷键也能实现该功能,不过对于我这种习惯用鼠标点击的人来说,还是“显示桌面”这个用起来爽。今天,一不小心,将“显示桌面...

Protel99SE英文版添加汉字

Protel99SE英文版添加汉字

需要使用PCB3.0中文输入程序,操作步骤如下: 双击打开ProtelHz.exe,输入汉字,点击确定。 如果双击ProtelHz.exe没有任何反应,请注意以下几点: ① 程序尽量不要放到较深的目录中,最好在三级以内。 ② 该程序所在的文件夹及所有上级文件夹,文件夹名最好不要使...

简单的谈一谈mklink

最近重装了一次系统,吸取了以前的经验教训,这次对个人资料的转移进行了比较充分的了解。 Vista和Win7本身自带了转移个人文件夹的功能。例如,我的文档,我的图片等都可以在【位置】选项卡里进行迁移。但是这个功能还有缺陷,因为很多软件的配置不能迁移,即appdata(隐藏文件夹)这个文件夹没法利用自带...

zencart迁移需要修改的地方

移植zencart,搬迁zencart:1.复制文件到新的服务器2.复制数据库3.修改配置文件    1)/includes/configure.php       //修改域名('HTTP_SERVER',&nb...

Proteus 7.6 SP4破解1.1+汉化包

下载地址:http://ishare.iask.sina.com.cn/f/6751561.html 说明: 使用方法 复制到安装文件夹 \Proteus 7 Professional\下运行。 中文系统可用, 不用改区域语言设置。 不要安装其他破解 更新历史 1.1(2010.02....

运放和比较器的区别及比较器技术参数

1、运放和比较器区别 (1)放大器与比较器的主要区别是闭环特性 放大器大都工作在闭环状态,所以要求闭环后不能自激。而比较器大都工作在开环状态更追求速度。对于频率比较低的情况放大器完全可以代替比较器(要注意输出电平),而比较器大部分情况不能当作放大器使用。 因为比较器为了提高速度进行优化,这种优化却减...

发表评论

访客

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