android.view.InflateException:填充类片段时出错

时间:2013-02-13 13:17:46

标签: android android-layout android-fragments android-viewpager android-nested-fragment

我收到以下错误:

02-13 12:37:05.015: E/AndroidRuntime(8766): FATAL EXCEPTION: main
02-13 12:37:05.015: E/AndroidRuntime(8766): android.view.InflateException: Binary XML file   line #9: Error inflating class fragment
02-13 12:37:05.015: E/AndroidRuntime(8766): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
...
02-13 12:37:05.015: E/AndroidRuntime(8766): Caused by: java.lang.IllegalArgumentException: Binary XML file line #9: Duplicate id 0x7f05005f, tag null, or parent id 0x0 with another fragment for com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment
02-13 12:37:05.015: E/AndroidRuntime(8766): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
02-13 12:37:05.015: E/AndroidRuntime(8766): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
02-13 12:37:05.015: E/AndroidRuntime(8766): ... 27 more

我正在创建一个带有操作栏sherlock的Android应用程序,并在选项卡之间进行水平滑动。对于每个选项卡,我加载了一个片段,我在其中一个中遇到了问题。 在这个片段中,我有一个嵌套片段,这对于pull-to-refresh列表是必不可少的。 因此,我有以下布局:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_people_layout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

<fragment
    android:id="@+id/frag_ptr_list"
    android:name="com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fastScrollEnabled="true"
    android:drawSelectorOnTop="false"
    android:divider="@android:color/transparent"
    android:layout_margin="10dp" />

<TextView
    android:id="@id/android:empty"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:text="@string/footer_loading_data" />

</LinearLayout>

以下代码片段:

public void onActivityCreated(Bundle savedInstanceState)
{
    super.onActivityCreated(savedInstanceState);
    activity = getActivity();
    mPullRefreshListFragment = (PullToRefreshListFragment) 
    activity.getSupportFragmentManager().findFragmentById(R.id.frag_ptr_list);
    ....
}

当我在选项卡之间滑动以及重新绘制片段时,问题出现了。

只是为了通知您,我正在使用支持库v4。

1 个答案:

答案 0 :(得分:1)

片段无法容纳其他片段。

但是......

使用当前版本的Android Support软件包 - 或API Level 17及更高级别的本机片段 - 您可以通过getChildFragmentManager()嵌套片段。请注意,这意味着您需要在API级别11-16上使用Android支持包版本的片段,因为即使这些设备上存在片段的本机版本,该版本也没有getChildFragmentManager()。

相关问题