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

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

xjtudll10年前 (2015-10-11)技术心得6880

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

远程桌面事件ID20499,没有明显的问题

问题:收到ID为20499的TerminalServices-RemoteConnectionManager警告事件,错误是:对于用户管理员来说,远程桌面服务花费的时间太长,无法从服务器\ server.domain.home加载用户配置。但是,找不到任何问题解决办法:在注册表编辑器中,找到并单击以...

Keil MDK 查看局部变量提示<not in scope>

Keil MDK 查看局部变量提示

现象: 在进行STM32开发的时候出现了,调试代码,添加变量Watch时,显示not in scope。 处理方式: 因为代码开了优化的处理,把优化改到Level0,就可以解决问题。...

SVN项目库错误Unsupported FS format svn: Expected FS format between '1' and '4'; found format '6'

SVN项目库错误Unsupported FS format svn: Expected FS format between '1' and '4'; found format '6'

问题: 利用SVN Dump版本库,命令行老是一闪而过 bat文件代码如下: cd .. F:\SubversionDB\websoft\svnserver\svnadmin.exe dump F:\SubversionDB\svn_repo\OSAL_51/ > f:/1.dump 这个ba...

SQL Server CLR常见错误

1.发布报错:执行 CREATE ASSEMBLY 时失败,因为该程序集是为公共语言用户时的不受支持的版本生成的 SQL SERVER 2008R2 不支持.net4.0, 需要把项目改成.net3.5 部署成功了 2.执行sql报错:禁止在 .NET Framework 中执行用户代码。启用...

如何备份iOS4.2.1SHSH文件

如何备份iOS4.2.1SHSH文件

本教程指导大家如何备份iOS4.2.1的SHSH文件,使用工具为TinyUmbrella4.21.02,支持全系列的iPhone4,iPhone3GS,iPhone3G,iPod Touch4G,iPod Touch3G,iPod Touch2G和iPad。 没有越狱的用户或者还没有升级iOS4....

金蝶K3 引出序时簿提示:cannot update database of object is read only

金蝶K3 引出序时簿提示:cannot update database of object is read only

金蝶K3引出序时簿提示:cannot update database of object is read only 解决办法: 更换引出路径...

发表评论

访客

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