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

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

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

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

Android 修改preferences summary 文字的颜色

参考资料: http://stackoverflow.com/questions/4081946/android-preferences-summary-default-color 需求: preferences summary的文字颜色通常是跟随系统的,例如黑色或白色,现需要根据不同情况改变su...

BOM各层级计算真实用量

BOM各层级计算真实用量

SELECT * FROM ( select 级别='1',A='A1',B='B1',用量='1',B真实用量='' UNION ALL select 级别='2',A='B1',B='C1',用量='2',B真实用量='' UNION ALL select 级别='3',A='C1...

PHP:Call to undefined function bindtextdomain()

all to undefined function bindtextdomain() bindtextdomain() 是系统函数为什么会出现上面情况 我的是 PHP/5.2.9 (PHP 4, PHP 5) bindtextdomain ? Set...

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里,原因不明。如图所示: 解决...

模数转换器的分类

直接ADC是将输入模拟电压直接转换成数字量,如并联比较型ADC和逐次比较型ADC; 间接ADC是先将输入模拟电压转换成时间或频率,然后再把这些中间量转换成数字量,如双积分型ADC。 并联比较型ADC 优点:采用各量级同时并行比较,各位输出码同时并行产生,因此转换速度快,转换速度与输出码位数无关...

计划状态的mrp计划订单,不需要了如何手工关闭?

审核状态的计划订单才能手工关闭,建议审核以后进行关闭...

发表评论

访客

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