活动和片段

时间:2013-04-05 06:08:49

标签: android android-fragments

这是交易,我有一个简单的应用程序,用户将登录并查看报告。 我的这些报告的基本架构包括一个标题片段,它将显示用户登录信息,然后是一个表格布局,它将保存报告内容和一个页脚片段,我在其中为我将提供的所有报告创建了一个选项菜单。 现在,我对每个报告都有不同的活动,我从 onOptionsItemSelected()开始/启动这些活动,如下所示:

getActivity().startActivity(intent);

第一个报告,菜单及其所有项目加载完美。 但是当我从菜单中选择菜单项时,我的应用程序停止提供以下异常:

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

我猜这种情况正在发生,因为下一个活动还包含那些片段(页眉和页脚)。 我的方法有误吗?我正在网上查找,但大量的信息让我感到困惑。任何帮助将不胜感激!

* 编辑:*

报告1的布局XML

<?xml version="1.0" encoding="utf-8"?>
<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">

    <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" />

    <TableLayout
        android:id="@+id/tblSummRep"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="4"
        android:padding="5dip">

    </TableLayout>
    <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" />   

</LinearLayout>

以上布局对于所有报告都是相同的

用于路由菜单itmes的代码(在页脚的片段中)如下:

@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;
    }

mm.RouteMenu()位于另一个类中,用于处理从数据库中提取要显示的项目等内容。

此外, con activity.getApplicationContext();,它位于 onAttach()事件中

0 个答案:

没有答案
相关问题