1. <small id='SVQBe'></small><noframes id='SVQBe'>

      <legend id='SVQBe'><style id='SVQBe'><dir id='SVQBe'><q id='SVQBe'></q></dir></style></legend>
    2. <i id='SVQBe'><tr id='SVQBe'><dt id='SVQBe'><q id='SVQBe'><span id='SVQBe'><b id='SVQBe'><form id='SVQBe'><ins id='SVQBe'></ins><ul id='SVQBe'></ul><sub id='SVQBe'></sub></form><legend id='SVQBe'></legend><bdo id='SVQBe'><pre id='SVQBe'><center id='SVQBe'></center></pre></bdo></b><th id='SVQBe'></th></span></q></dt></tr></i><div id='SVQBe'><tfoot id='SVQBe'></tfoot><dl id='SVQBe'><fieldset id='SVQBe'></fieldset></dl></div>
      <tfoot id='SVQBe'></tfoot>
        <bdo id='SVQBe'></bdo><ul id='SVQBe'></ul>

    3. 第二次在对话框中膨胀片段时出错

      时间:2023-08-31
        <bdo id='iYrX0'></bdo><ul id='iYrX0'></ul>

            <i id='iYrX0'><tr id='iYrX0'><dt id='iYrX0'><q id='iYrX0'><span id='iYrX0'><b id='iYrX0'><form id='iYrX0'><ins id='iYrX0'></ins><ul id='iYrX0'></ul><sub id='iYrX0'></sub></form><legend id='iYrX0'></legend><bdo id='iYrX0'><pre id='iYrX0'><center id='iYrX0'></center></pre></bdo></b><th id='iYrX0'></th></span></q></dt></tr></i><div id='iYrX0'><tfoot id='iYrX0'></tfoot><dl id='iYrX0'><fieldset id='iYrX0'></fieldset></dl></div>

                <tbody id='iYrX0'></tbody>
              • <small id='iYrX0'></small><noframes id='iYrX0'>

                <tfoot id='iYrX0'></tfoot>
              • <legend id='iYrX0'><style id='iYrX0'><dir id='iYrX0'><q id='iYrX0'></q></dir></style></legend>

              • 本文介绍了第二次在对话框中膨胀片段时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我在一个 Activity 中有以下代码,它为包含片段的布局启动一个对话框.

                I have the following code in an Activity that starts a dialog for a layout that contains a fragment.

                ...
                case R.id.pick_resource:
                        dialog = new Dialog(this);
                        dialog.setContentView(R.layout.resource_picker);
                        dialog.setCancelable(true);
                        dialog.setTitle("Pick a resource");
                        dialog.show();
                

                这在应用程序启动后第一次运行良好,但是当对话框退出并稍后再次调用时,我得到了这个堆栈跟踪:

                This works very well the first time after application start, but when the dialog is quit and later called again, I get this stack trace:

                08-10 10:47:33.990: ERROR/AndroidRuntime(26521): FATAL EXCEPTION: main
                        android.view.InflateException: Binary XML file line #7: Error inflating class fragment
                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:688)
                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
                        at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
                        at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
                        at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
                        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:224)
                        at android.app.Dialog.setContentView(Dialog.java:449)
                        at org.rhq.pocket.StartActivity.onOptionsItemSelected(StartActivity.java:118)
                        at android.app.Activity.onMenuItemSelected(Activity.java:2390)
                        at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:852)
                        at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:153)
                        at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:956)
                        at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:174)
                        at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:85)
                        at android.view.View.performClick(View.java:3100)
                        at android.view.View$PerformClick.run(View.java:11644)
                        at android.os.Handler.handleCallback(Handler.java:587)
                        at android.os.Handler.dispatchMessage(Handler.java:92)
                        at android.os.Looper.loop(Looper.java:126)
                        at android.app.ActivityThread.main(ActivityThread.java:3997)
                        at java.lang.reflect.Method.invokeNative(Native Method)
                        at java.lang.reflect.Method.invoke(Method.java:491)
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
                        at dalvik.system.NativeStart.main(Native Method)
                        Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f090007, tag null, or parent id 0xffffffff with another fragment for org.rhq.pocket.ResourcePickerFragement
                        at android.app.Activity.onCreateView(Activity.java:4089)
                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:664)
                        ... 24 more
                

                任何想法,可能导致此异常的原因是什么?我必须以某种方式卸载片段吗?

                Any idea, what may cause this exception? Do I have to unload the fragment somehow?

                推荐答案

                你的布局中的片段是否有 android:id 属性?

                Does the fragment in your layout have an android:id attribute?

                我怀疑这是因为每次布局膨胀时都会实例化片段,第一次没有使用 ID,但第二次 FragmentManager 仍然认为您的 Fragment 是活动的,因此 ID 被认为是重复的.

                I suspect this is because the fragment is instantiated each time your layout is inflated, the first time the ID isn't being used, but the second time the FragmentManager still thinks your Fragment is alive, so the ID is considered a duplicate.

                尝试从片段中删除 android:id 属性(如果存在),或者添加一个占位符布局,例如 framelayout 并使用片段事务在每次创建对话框时动态添加片段.

                Try removing the android:id attribute from your fragment if it exists, or add a placeholder layout such as a framelayout and use a fragmenttransaction to dynamically add the fragment each time your dialog is created.

                这篇关于第二次在对话框中膨胀片段时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Android:如何创建一个透明的以对话框为主题的活动 下一篇:Android:首次运行弹出对话框

                相关文章

                最新文章

                  <tfoot id='h9Ip6'></tfoot>
                1. <i id='h9Ip6'><tr id='h9Ip6'><dt id='h9Ip6'><q id='h9Ip6'><span id='h9Ip6'><b id='h9Ip6'><form id='h9Ip6'><ins id='h9Ip6'></ins><ul id='h9Ip6'></ul><sub id='h9Ip6'></sub></form><legend id='h9Ip6'></legend><bdo id='h9Ip6'><pre id='h9Ip6'><center id='h9Ip6'></center></pre></bdo></b><th id='h9Ip6'></th></span></q></dt></tr></i><div id='h9Ip6'><tfoot id='h9Ip6'></tfoot><dl id='h9Ip6'><fieldset id='h9Ip6'></fieldset></dl></div>
                  <legend id='h9Ip6'><style id='h9Ip6'><dir id='h9Ip6'><q id='h9Ip6'></q></dir></style></legend>

                  <small id='h9Ip6'></small><noframes id='h9Ip6'>

                    <bdo id='h9Ip6'></bdo><ul id='h9Ip6'></ul>