I am new to android studio and am having some trouble with starting a fragment from an activity. I used code from on here to display the fragment and it was working up until now. I am using a third party library called 'DecoView' which needs to extend fragment, all the code is in 'LineDetails' (its too long to add all code). Does anyone recognise this error below?
Thank you in advance!
LINE DETAILS XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:id="@+id/fragment_place"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<com.hookedonplay.decoviewlib.DecoView
android:layout_width="250dp"
android:layout_height="200dp"
android:id="@+id/dynamicArcView"
android:layout_marginLeft="40dp"
android:layout_marginRight="8dp"
android:layout_marginTop="5dp">
</com.hookedonplay.decoviewlib.DecoView>
<EditText
android:id="@+id/actual"
android:inputType="number"
android:layout_width="150dp"
android:layout_height="46dp"
android:background="@drawable/border"
android:gravity="center"
android:hint="Enter Actual"
android:text=""
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="15sp"
android:layout_marginStart="26dp"
android:layout_alignBottom="@+id/textPercentage"
android:layout_alignStart="@+id/dynamicArcView" />
<Button
android:id="@+id/actual_btn"
android:layout_width="68dp"
android:layout_height="50dp"
android:background="@drawable/actualbutton"
android:shadowColor="#A8A8A8"
android:text="+"
android:textColor="#FFFFFF"
android:layout_above="@+id/textViewProgress"
android:layout_toEndOf="@+id/actual"
android:layout_marginLeft="12dp"/>
<TextView
android:id="@+id/textViewProgress"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_marginTop="15dp"
android:layout_below="@+id/actual"
android:layout_alignEnd="@+id/actual_btn"
android:layout_marginEnd="14dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:textSize="40sp"
android:id="@+id/textPercentage"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp"
/>
<TextView
android:id="@+id/textViewLineType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="86dp"
android:text=""
android:textSize="40dp"
android:textAlignment="center"
android:textStyle="bold"
android:textColor="#f15623"
android:layout_alignTop="@+id/dynamicArcView"
android:layout_toEndOf="@+id/dynamicArcView" />
<Button
android:id="@+id/buttonViewDetails"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@mipmap/info"
android:layout_marginLeft="250dp"
android:onClick="verifyButton"
android:layout_alignParentBottom="true"
android:layout_marginBottom="14dp" />
</RelativeLayout>
</RelativeLayout>
<fragment
android:id="@+id/fragment_name"
class="com.almac.tracker.LineDetails"
android:layout_width="match_parent"
android:layout_height="match_parent" />
"xmlns:android="http://schemas.android.com/apk/res/android"
is missing
use below code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<fragment
android:id="@+id/fragment_name"
class="com.almac.tracker.LineDetails"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Try adding
tools:context="com.yourpackagehere.FragmentThatIsInflatingTheXml">
to your first layout, the Relative one. Pls note that you have to change "yourpackagehere" with the name of your package and "FragmentThatIsInflatingTheXml" with the name of the actual Fragment
You said that DecoView extends a fragment so it should be added like this:
<fragment
android:id="@+id/fragment_id"
android:name="com.hookedonplay.decoviewlib.DecoView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.