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

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

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

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

WCF:在 ServiceModel 客户端配置部分中,找不到引用协定

环境:VS2010 + C#(DLL) + WCF 即我使用C#编写了一个DLL,在DLL里面远程调用WCF服务,然后EXE程序在调用DLL里面的接口时,出现了如下错误: System.InvalidOperationException: 在 ServiceModel 客户端配置部分中,找不到引用协...

Xcode Warning: The Copy Bundle Resources build phase contains this target's Info.plist file

Xcode Warning: The Copy Bundle Resources build phase contains this target's Info.plist file

问题: 编译时,提示The Copy Bundle Resources build phase contains this target's Info.plist file 原因: Info.plist被添加到了Copy Bundle Resources里,原因不明。如图所示: 解决...

水晶报表的文本对象中怎么插入换行符

水晶报表的文本对象中如何插入换行符?我的文本对象要显示的值是从RichTextBox中读出来的,但文本对象不能显示“\n”,怎么让文本对象换行呢?------解决方案--------------------1:不要用文本对象,用公式2:把\n替换成水晶报表里的换行符号Replace(字段,'...

如何统计SQL语句查询出来的条数

可以通过count函数来实现。 sqlOne:select * from tablename1 where id>5;此语句查询出来多条记录,之后看做一个新的表。 sqlTwo:select conut(*) from (select * from tablename1 where id>...

如何从远程桌面复制文件

如何从远程桌面复制文件

工作学习中,经常需要用到远程桌面,远程桌面确实很方便,但每次要将本地的东西拷贝到远程电脑或将远程电脑上的东西拷贝到本地时,都是用U盘来传递文件,这样就相当不方便了。近日,偶然看了远程桌面的帮助,发现其本身就是带文件复制、粘贴功能的,只是默认没有开启而已。 第一步:在远程桌面连接窗口,单击【选项】,...

运放主要参数

集成运放的参数较多,其中主要参数分为直流指标和交流指标。 其中主要直流指标有输入失调电压、输入失调电压的温度漂移(简称输入失调电压温漂)、输入偏置电流、输入失调电流、输入偏置电流的温度漂移(简称输入失调电流温漂)、差模开环直流电压增益、共模抑制比、电源电压抑制比、输出峰-峰值电压、最大共模输入电压...

发表评论

访客

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