Android 如何将膨胀碎片固定在轮胎上

Android 如何将膨胀碎片固定在轮胎上,android,android-fragments,Android,Android Fragments,我正在尝试为我的片段制作页脚。我成功地做到了这一点,但当我第一次加载此片段时仍然存在问题,它工作正常,但当我更改导航抽屉中的片段并尝试第二次获取此片段时,应用程序崩溃和日志错误显示错误: android.view.InflateException: Binary XML file line #17: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInfl

我正在尝试为我的片段制作页脚。我成功地做到了这一点,但当我第一次加载此片段时仍然存在问题,它工作正常,但当我更改导航抽屉中的片段并尝试第二次获取此片段时,应用程序崩溃和日志错误显示错误:

 android.view.InflateException: Binary XML file line #17: Error inflating class fragment
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
 Caused by: java.lang.IllegalArgumentException: Binary XML file line #17: 
 Duplicate id 0x7f070084, tag null, or parent id 0x7f070082 with another fragment for   com.example.user.unchained.FooterHome
所以任何人都有办法解决这个问题

创建视图的
功能:

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        v =   inflater.inflate(R.layout.fragment_homes, container, false);

        listView = (ListView) v.findViewById(R.id.homeList);

        l = new HomeListAdapter(this, homeList);
        listView.setAdapter(l);

        return v;

    }
<RelativeLayout 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:background="@color/dark_grey"
android:id="@+id/fHome"
tools:context="com.example.user.unchained.HomesActivity$PlaceholderFragment">

<ListView
    android:id="@+id/homeList"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:dividerHeight="1dp"
    android:choiceMode="singleChoice"
    android:listSelector="@drawable/list_row_selector" />

<fragment
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:name="com.example.user.unchained.FooterHome"
    android:layout_alignParentBottom="true"
    android:id="@+id/foo"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    tools:layout="@layout/footer_home" />


 </RelativeLayout>
主布局XML:

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        v =   inflater.inflate(R.layout.fragment_homes, container, false);

        listView = (ListView) v.findViewById(R.id.homeList);

        l = new HomeListAdapter(this, homeList);
        listView.setAdapter(l);

        return v;

    }
<RelativeLayout 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:background="@color/dark_grey"
android:id="@+id/fHome"
tools:context="com.example.user.unchained.HomesActivity$PlaceholderFragment">

<ListView
    android:id="@+id/homeList"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:dividerHeight="1dp"
    android:choiceMode="singleChoice"
    android:listSelector="@drawable/list_row_selector" />

<fragment
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:name="com.example.user.unchained.FooterHome"
    android:layout_alignParentBottom="true"
    android:id="@+id/foo"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    tools:layout="@layout/footer_home" />


 </RelativeLayout>

页脚布局XML。

<FrameLayout 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:background="#272822"
android:id="@+id/homeFooter"
tools:context="com.example.user.unchained.FooterHome">


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="What's New ?"
android:textSize="16dip"
android:layout_marginTop="12dip"
android:layout_marginLeft="10dip"
android:drawableLeft="@drawable/status"
android:id="@+id/watsN"
android:textColor="@color/connexion_button"
android:layout_gravity="left|top" />


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text=" | "
    android:textSize="25dip"
    android:layout_marginTop="6dip"
    android:layout_marginLeft="145dip"
    android:textColor="@color/connexion_button"
    android:layout_gravity="left|top" />


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Check In"
    android:textSize="16dip"
    android:layout_marginTop="12dip"
    android:layout_marginLeft="165dip"
    android:drawableLeft="@drawable/checkin"
    android:id="@+id/checkIn"
    android:textColor="@color/connexion_button"
    android:layout_gravity="left|top" />


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text=" | "
    android:textSize="25dip"
    android:layout_marginTop="6dip"
    android:layout_marginLeft="265dip"
    android:textColor="@color/connexion_button"
    android:layout_gravity="left|top" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text=" Picture"
    android:textSize="16dip"
    android:layout_marginTop="12dip"
    android:layout_marginLeft="290dip"
    android:drawableLeft="@drawable/camera"
    android:id="@+id/postPic"
    android:textColor="@color/connexion_button"
    android:layout_gravity="left|top" />

 </FrameLayout>

您的错误消息显示:“重复id 0x7f070084…”这让我认为,如果片段的根具有id,则无法将同一片段添加两次

这只是一个猜测,但是在根元素上不要使用
android:id
属性

更新

查看是否可以找出错误消息所涉及的ID。检查你的R类。它是从布局xml文件自动生成的,在布局xml文件中,它为您添加的每个id生成唯一的编号,并使用“@+id/some_name”表示法

错误消息提到id为0x7f070084或id为0x7f070082的问题。它没有提到他们的名字,这可能会给你一个更好的提示,在哪里寻找问题

但是您可以在自动生成的R类中查找名称。在Android Studio上,您可以在以下路径中找到R类:app/build/generated/source/R/debug/com/example/user/uncheed/debug。我不知道Eclipse是否使用了不同的路径,但我相信您可以找到它


打开R.java文件并搜索错误消息中提到的id号。

首先更改
新的HomeListAdapter(此,homeList)
。如果它接收到一个上下文作为第一个参数,那么应该传递getActivity(),而不是这个参数。为什么要传递getActivity?我的列表是一个片段,而不是一个活动!HomeListAdapter构造函数的第一个参数是什么?一个片段而不是一个活动!上面也写着“或”。因此,可能是错误不在没有确切id的id上?