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

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

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

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

OSX:如何移动NSWindow而同时不移动其子Window

参考资料: http://stackoverflow.com/questions/7657132/how-to-move-an-nswindow-without-moving-child-nswindows 问题: 应用程序有个主window,在主window里,新建了一个子window。 每当移动...

光耦,大有用处

光耦,百度百科是这样说的:耦合器(optical coupler,英文缩写为OC)亦称光电隔离器,简称光耦,是开关电源电路中常用的器件。耦合器以光为媒介传输电信号。它对输入、输出电信号有良好的隔离作用,所以,它在各种电路中得到广泛的应用。目前它已成为种类最多、用途最广的光电器件之一。光耦合器一般由三...

金蝶K3:直接SQL报表中进行核算项目数据授权控制的方法

--【第一步】: --根据核算项目类别ID,查询到对应核算项目的数据授权表及查看、修改、删除的权限字段名和权限掩码 --例如查出客户的数据授权表为Access_t_Organization --几乎所有的核算项目的查看、修改、删除的权限字段名和权限掩码都是以下这样: -...

Android BLE:onServicesDiscovered(BluetoothGatt gatt, int status) 没有回调过

问题: .discoverServices()调用之后,却永远不回调onServicesDiscovered(BluetoothGatt gatt, int status) 基本代码如下: public void onConnectionStateChange(BluetoothGatt gatt...

Android studio中右键项目没有subversion(SVN)解决办法

Android studio中右键项目没有subversion(SVN)解决办法

解决办法: file->settings->version control 将<project>后面的none改成subversion点击OK即可...

模数转换器主要技术指标

分辨率(Resolution) 指数字量变化一个最小量时模拟信号的变化量, 定义为满刻度与2n的比值。分辨率又称精度,通常以数字信号的位数来表示。 转换速率(Conversion Rate) 指完成一次从模拟转换到数字的AD转换所需的时间的倒数。 积分型AD的转换时间是毫秒级属低速AD,逐次...

发表评论

访客

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