每当我从活动转到片段时如何获取实例

时间:2019-01-24 11:13:51

标签: android android-fragments

我已经制作了导航抽屉,每当我单击导航项时,它将进入片段,现在我的基地是我实现了导航视图的活动,现在的问题是我每次导航时都没有片段以自己的实例为例,我在soap invoke方法中遇到了异常

    private void selectItem(int position) {
    Fragment fragment = null;
    Class fragmentClass;

    switch (position) {
        case 0:
            AppDelegate.launchTargetActivity();

            mllDashboard.setVisibility(View.GONE);
            mtv_Title.setText("Target vs Achievment");
            break;

        case 1:
            fragment = new SalesFragment();
            mllDashboard.setVisibility(View.GONE);

            break;
        case 2:
            fragment = new SalesFragment();
            mllDashboard.setVisibility(View.GONE);

            break;
        case 3:
            fragment = new HrFragment();
            mllDashboard.setVisibility(View.GONE);

            break;
        case 4:
            fragment =  schemefragment.newInstance();
            mllDashboard.setVisibility(View.GONE);


            break;

        default:
            break;
    }

        if (fragment != null) {
            FragmentManager fragmentManager = getSupportFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

            mDrawerList.setItemChecked(position, true);
            mDrawerList.setSelection(position);
            mDrawerLayout.closeDrawer(mDrawerList);

        } else {
            Log.e("MainActivity", "Error in creating fragment");
        }


    }

0 个答案:

没有答案