1
我想插入一個片段到另一個,我已經成功做到這一點,直到我午餐主要片段爲第一次它的工作,但當我試圖重新加載片段的應用程序崩潰,我有這個錯誤: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
我已經嘗試了兩種解決方案:第一個是覆蓋onDestroyView
方法。二進制XML文件行#17:重複的id,標記空或父ID與另一個片段
@Override
public void onDestroyView() {
super.onDestroyView();
PlaceholderFragment f = (PlaceholderFragment) getFragmentManager()
.findFragmentById(R.id.f);
if (f != null)
getFragmentManager().beginTransaction().remove(f).commit();
}
,第二個是讓馳騁於該視圖已經存在,並且嘗試新的一個顯示之前將其刪除
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (v != null) {
ViewGroup parent = (ViewGroup) v.getParent();
if (parent != null)
parent.removeView(v);
}
v = inflater.inflate(R.layout.fragment_homes, container, false); }
即使兩個方案不工作對我來說,仍然繩拉問題請任何其他解決方案,您可以提出
主片段XML佈局:
<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/f"
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="#000"
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>