Note that there are some explanatory texts on larger screens.

plurals
  1. POActivities and fragments
    primarykey
    data
    text
    <p>Here's the deal, i have a simple application in which u user will log in and view reports. My basic architecture of these reports consists of a header fragment which will display user login info, then a table layout which will hold the report content and a footer fragment in which i have created an option menu for all the report i will be providing. Now, i have different activities for each report and i start/launch these activites from the <strong>onOptionsItemSelected()</strong> as follows:</p> <p><code>getActivity().startActivity(intent);</code></p> <p>The first report, menu and all its items load perfectly. But when i select a menu item from the menu my app stops giving the following exception:</p> <pre><code>04-04 18:29:49.670: E/AndroidRuntime(1123): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.Report2}: android.view.InflateException: Binary XML file line #10: Error inflating class fragment </code></pre> <p>I am guessing that this is happening because the next activity also contains those fragments(header and footer). Is my approach wrong? I am looking up on the net, but loads of info leaves me confused at the end. Any help would be appreciated!</p> <p>*<em>EDIT : *</em></p> <p>layout XML for report 1</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout 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:baselineAligned="false" android:gravity="center" android:orientation="vertical"&gt; &lt;fragment android:name="com.example.HeaderFragment" android:layout_width="match_parent" android:layout_height="0dp" android:layout_gravity="center" android:layout_weight="1" android:gravity="center_horizontal" tools:layout="@layout/header_fragment" /&gt; &lt;TableLayout android:id="@+id/tblSummRep" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="4" android:padding="5dip"&gt; &lt;/TableLayout&gt; &lt;fragment android:name="com.example.FooterFragment" android:layout_width="match_parent" android:layout_height="0dp" android:layout_gravity="center" android:layout_weight="1" android:gravity="center_horizontal" tools:layout="@layout/footer_fragment" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>the above layout will be same for all reports</p> <p>the code for routing the menu itmes(in the class for footer fragment) is as follows : </p> <pre><code>@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection int switchTo = mm.routeMenu(item, con); switch (switchTo) { case 2: intent = new Intent(con, Report2.class); isAct = "Y"; break; case 3: intent = new Intent(con, Report3.class); isAct = "Y"; break; case 4: intent = new Intent(con, Report4.class); isAct = "Y"; break; case 5: intent = new Intent(con, Report5.class); isAct = "Y"; break; case 6: intent = new Intent(con, Report6.class); isAct = "Y"; break; default: super.onOptionsItemSelected(item); } if(isAct.toUpperCase().equals("Y")){ if(Login.lstLogin != null){ getActivity().startActivity(intent); } } return true; } </code></pre> <p><strong>mm.RouteMenu()</strong> is in in a different class which handles things like fetching the items to be diplayed from the database.</p> <p>Also, <strong>con</strong> is <code>activity.getApplicationContext();</code> which is in the <strong>onAttach()</strong> event</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload