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

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

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

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

Proteus 7.7 SP2破解及下载

不得不说,Proteus升级的太快,7.6SP4国人还没破解完好,7.7 SP2和谐版就有了。我倒。 Proteus 7.7 SP2相比7.6 SP4只是多了几个PIC和MSP430的模型,貌似MSP430新增的还是2xx系列。 下载地址: 国外网站,请单击进入网页下载,只能用单线程,多线程下载器无...

穆斯林祈祷时间定义

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

ESD及静电的特点

什么是ESD ESD是代表英文Electrostatic Discharge[1] 即“静电放电”的意思。ESD是本世纪中期以来形成的以研究静电的产生与衰减、静电放电模型、静电放电效应如电流热(火花)效应(如静电引起的着火与爆炸)和电磁效应(如电磁干扰)等的学科。近年来随着科学技术的飞速发展、微电...

CRC查表法——表的由来

为了更容易理解这篇文章,拿出纸笔跟着算一遍吧。文中的一些假定:a0,a1,b0,b1,b2,b3,c1,c2,c3等等,拿笔将其含义记下来,免得思维混乱。 查表法实际上利用的是XOR运算的交换律和结合律,即(A XOR B )XOR C = A XOR (B XOR C) 我们再以一个简单的例子来...

C#获取文件全路径、目录、扩展名、文件名称

class Program     {         static void Main(string[] args)       &nbs...

NSButton——设定背景图片Scale

NSButton——设定背景图片Scale

参考资料: http://stackoverflow.com/questions/5851923/how-to-scale-axes-independently-at-runtime-on-an-nsbutton 代码方式: NSButton *someButton; NSButtonCell...

发表评论

访客

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