Android的膨胀的布局包含片段片段、布局、Android

2023-09-07 02:02:23 作者:[有梦才不怕痛]

这是什么问题? 我怎么能膨胀的布局包含片段? 我不知道该错误信息的含义。 请帮我。 谢谢

what is the problem? how can i inflate a layout contains fragment? i dont know the meaning of the error message. Please help me. Thank you

错误信息

09-01 18:44:58.698: E/AndroidRuntime(20617): Caused by:
java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f080002,
tag null, or parent id 0x0 with another fragment for com.example.testing.ListFragment

我的code

My Code

public static class DummySectionFragment extends Fragment {
    public DummySectionFragment() {
    }

    public static final String ARG_SECTION_NUMBER = "section_number";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        Log.e("555", "hello");
        return inflater.inflate(R.layout.main, null);

        /*
        TextView textView = new TextView(getActivity());
        textView.setGravity(Gravity.CENTER);
        Bundle args = getArguments();
        textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
        return textView;*/
    }
}

main.xml中

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <fragment
        android:id="@+id/listFragment"
        android:layout_width="150dip"
        android:layout_height="match_parent"
        android:layout_marginTop="?android:attr/actionBarSize"
        class="com.example.testing.ListFragment" ></fragment>

    <fragment
        android:id="@+id/detailFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.example.testing.DetailFragment" >
        <!-- Preview: layout=@layout/details -->
    </fragment>

</LinearLayout>

哎呀!你的问题不能提交,因为:

Oops! Your question couldn't be submitted because:

您的文章没有太多的上下文来解释code段;请更清楚地解释您的方案。

Your post does not have much context to explain the code sections; please explain your scenario more clearly.

推荐答案

您不能有一个片段在另一个片段

You can not have a Fragment inside another Fragment.