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

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

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

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

SVN修改Log信息

SVN修改Log信息

SVN默认是不能修改Log的,强行修改会报错:Repository has not been enabled to accept revision propchanges,ask the administrator to create a pre-revprop-change hook 如果需要修改...

ios宏: 判断是否是retina屏,是否iPad,设备判断(4,5,5s,6等)

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) #def...

ios ble:didDiscoverPeripheral没有回调

参考资料: http://stackoverflow.com/questions/26320578/diddiscoverperipheral-not-been-called-after-advertising-another-ios-device 问题: 启动scan之后,didDiscoverP...

AutoCAD 2010两则小设置

AutoCAD 2010两则小设置

以前一直用AutoCAD2004,最近升级为AutoCAD2010,发现使用有些不同,尤其是一些设置,很难找到入口,所以也就不知从何设置。 一、AutoCAD2010更改图纸背景为黑色 AutoCAD2010默认图纸背景是白色,而之前大量的图纸都是在黑色背景下完成的。如果背景不更改为黑色,看起来很不...

CC2541功耗测试结果

CC2541功耗测试结果

测试环境: 1、CC2541开发板 2、使用heartrate工程,修改心率发送间隔时间为1秒(原来是2秒) 测试结果: 慢速广播 10 uA 快速广播 2 mA 仅定时器运行:1.2 uA(蓝牙关闭) 休眠:0.34 uA 与手机连接时刻:1 mA 约持续10秒 保持连接状态(1秒发送一次心率值...

单片机IO输入输出配置

单片机IO输入输出配置

单片机IO简单的来说,分为输入和输出两种配置。而输入和输出里,又有一些更详细的配置。如下图所示: 输出配置,比较常见的有四种: (1) High-impedance output 高阻输出,可以简单的理解为悬空状态,它的输出随外界改变而改变。 (2) P-channel open drain...

发表评论

访客

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