1

我在操作栏选项卡和让主/详细信息布局工作时遇到问题。

我有一个主/细节工作,但我现在正在添加选项卡,所以我可以选择不同的布局。但是,它似乎因错误而崩溃:

04-27 13:00:45.805: E/AndroidRuntime(5161): android.view.InflateException: Binary XML file line #24: Error inflating class fragment
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at com.example.example.masterdetail_tabs.Tab1Fragment.onCreateView(Tab1Fragment.java:17)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.app.Fragment.performCreateView(Fragment.java:1695)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1255)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.app.BackStackRecord.run(BackStackRecord.java:672)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.os.Handler.handleCallback(Handler.java:725)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.os.Looper.loop(Looper.java:137)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.app.ActivityThread.main(ActivityThread.java:5041)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at java.lang.reflect.Method.invokeNative(Native Method)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at java.lang.reflect.Method.invoke(Method.java:511)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at dalvik.system.NativeStart.main(Native Method)
04-27 13:00:45.805: E/AndroidRuntime(5161): Caused by: java.lang.IllegalArgumentException: Binary XML file line #24: Duplicate id 0x7f060001, tag null, or parent id 0x0 with another fragment for com.example.example.masterdetail_tabs.ItemListFragment
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
04-27 13:00:45.805: E/AndroidRuntime(5161):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)

我创建了一个简单的应用程序来重新创建问题(不知道这是否是一个问题,但我在真正的应用程序中使用 actionbarsherlock)

https://github.com/abidk/android_masterdetail_tab_issue

有谁知道我做错了什么?

4

1 回答 1

1

如果有人想知道解决方案是用框架布局替换 *_twopane.xml 中的片段,然后以编程方式添加列表组件。

getFragmentManager().beginTransaction()
    .replace(R.id.item_list, new ItemListFragment())
    .commit();
于 2013-04-28T09:26:19.743 回答