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

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

xjtudll9年前 (2015-10-11)技术心得5700

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

Altium打印设置

Altium打印设置

Altium Designer打印有两种方法,一种是利用打印机或者虚拟打印机,将原理图或PCB打印出来;一种是利用其自带的Smart PDF功能将原理图或PCB打印成PDF文档。本文旨在讲述这两种方法。 一、利用打印机打印 首先,设置文档的打印信息。【File】->【Page Setup】...

插件中获取多级审核级次

oMultiMgr.CurrentLevel   Private Sub m_BillInterface_AfterLoadBill()     Dim oMultiMgr As Object     Set oMultiMgr...

Android Studio Warning:Not annotated parameter overrides @NonNull parameter

问题: android studio提示:Not annotated parameter overrides @NonNull parameter 分析: Warning:The @NonNull annotation can be used to indicate that a given par...

C# textBox框实现输入下拉列表

C# textBox框实现输入下拉列表

textBox框像百度搜索出现下拉列表的样式,如图: 重点就是要关注:AutoCompleteMode和AutoCompleteSource两种属性。 具体实现代码如下: 将此方法在frmLogin_Load事件里加载, private void bindTxt() {   ...

Android 6.0:收不到BluetoothDevice.ACTION_FOUND广播

Android 6.0:收不到BluetoothDevice.ACTION_FOUND广播

参考资料: http://stackoverflow.com/questions/32656510/register-broadcast-receiver-dynamically-does-not-work-bluetoothdevice-action-f https://developer.and...

金蝶K3老单原生字段设置必录

修改单据模板ICTemplate里对应的字段 select * from ICTemplate where FCaption like '%部门%' and FID = 'D01' 修改FMustInput字段,改为1,即true,则为必录...

发表评论

访客

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