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

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

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

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

AutoCAD转Altium

以前写过一篇文章,讲述了AutoCAD如何转Protel99SE [AutoCAD转Protel99SE及丢线问题解决] 现在公司不允许用Protel99SE了(因版权问题),买了正版的Altium。因此,要将AutoCAD转Altium,其实是可以用上面的办法的,那个办法依旧有效。 还有一个...

Eclipse导入Android工程,出现default与Displaying的问题解决

Eclipse导入android工程时出现如下提示: [15:04:03 - XXX] 'default' is not a best match for any device/locale combination.  [ 15:04:03 - XXX] Displaying it wi...

sharepoint 安装Office Web Applications 报错

sharepoint 安装Office Web Applications 报错,如下: 未能从程序集“Microsoft.Office.Excel.Server.MossHost, Version=14.0.0.0, Culture=neutral, PublicKeyToken=...

OKI编译器路径设置及uEase驱动的安装

OKI编译器路径设置及uEase驱动的安装

1、OKI编译器系统路径的设置 OKI的编译器环境IDEU8默认是安装到C盘的。在安装时,若选择到其他盘,则在默认设置下无法编译成功,编译报错。原因是默认的路径都是在C盘,要解决这个问题,必须重新设置系统路径。 设置步骤:File -> Environment settings -> S...

一些奇葩问题

1、排针居然有电阻 问题描述: 排针的不同PIN之间用万用表测量居然是有电阻的 原因: 排针质量有问题,老化   2、按键 问题描述: 导通电阻不是0,200欧姆~2k欧姆不等 原因: 按键老化 这种有导通电阻的,对于独立式按键来说影响不大,对于AD键盘而言,影响将很明显,很有可能导致误判...

金蝶K3中用户组和用户的权限导入导出

金蝶K3中用户组和用户的权限导入导出

帐套管理-帐套-用户引入引出...

发表评论

访客

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