I'm trying to insert a fragment to another and I’ve succeed to do this until I’ve lunch the main fragment for the first time it's working but when I’m trying to reload the fragment the app crash, and i have this error: 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 i have tried two solutions : the first one is to override the onDestroyView method.
@Override
public void onDestroyView() {
super.onDestroyView();
PlaceholderFragment f = (PlaceholderFragment) getFragmentManager()
.findFragmentById(R.id.f);
if (f != null)
getFragmentManager().beginTransaction().remove(f).commit();
}
And the second one is to make surf in the that the view is already exist and try to remove it before the new one display
@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); }
Even if the two solutions doesn’t work for me and still hove the problem please any other solutions can you propose
The Main fragment XML Layout :
<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>
The fragment XML Layout :
<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>
0 comments:
Post a Comment