Example usage for android.app FragmentManager beginTransaction

List of usage examples for android.app FragmentManager beginTransaction

Introduction

In this page you can find the example usage for android.app FragmentManager beginTransaction.

Prototype

public abstract FragmentTransaction beginTransaction();

Source Link

Document

Start a series of edit operations on the Fragments associated with this FragmentManager.

Usage

From source file:com.example.search.car.pools.welcome.java

private void selectItem(int position) {
    setTitle(mPlanetTitles[position]);//w ww .  j  av a 2  s .  com

    // update the main content by replacing fragments
    Fragment fragment = null;
    if (mPlanetTitles[position].equals("Cities")) {
        layout = "Cities";
        fragment = new Cities();
        frag_tag = "Cities";

        // } else if (mPlanetTitles[position].equals("Promote Carpooling"))
        // {
        // layout = "Promote Carpooling";
        // fragment = new Promote_Carpooling();
        // frag_tag = "Promote Carpooling";
        // } else if (mPlanetTitles[position].equals("Create Listing")) {
        // layout = "Create Listing";
        // fragment = new Create_Listing();
        // frag_id = 3;
        // frag_tag = "Create Listing";
        // } else if (mPlanetTitles[position].equals("About Us")) {
        // layout = "About Us";
        // fragment = new About_Us();
        //
        // } else if (mPlanetTitles[position].equals("Blog")) {
        // layout = "Blog";
        // fragment = new blog();

    } else if (mPlanetTitles[position].equals("Dashboard")) {
        layout = "Dashboard";
        fragment = new dashboard();
        frag_tag = "Dashboard";
        // getActionBar().setTitle("My Profile");
    } else {
        layout = "Search";
        frag_tag = "Search";
        fragment = new Search();
    }

    FragmentManager fm = getFragmentManager();
    FragmentTransaction fragmentTransaction = fm.beginTransaction();
    fragmentTransaction.replace(R.id.content_frame, fragment, frag_tag);
    fragmentTransaction.commit();
    /*
     * Bundle args = new Bundle();
     * args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
     * fragment.setArguments(args);
     * 
     * FragmentManager fragmentManager = getFragmentManager();
     * fragmentManager.beginTransaction().replace(R.id.content_frame,
     * fragment).commit();
     */
    // update selected item and title, then close the drawer
    // mDrawerList.setItemChecked(position, true);

    mDrawerLayout.closeDrawer(mDrawerList);

}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

/**
 * Show the spreadsheet fragment./* w  w w.  ja v a2s. com*/
 * 
 * @param createNew
 */
public void showSpreadsheetFragment(boolean createNew) {
    this.setCurrentFragmentType(ViewFragmentType.SPREADSHEET);
    this.updateChildViewVisibility(ViewFragmentType.SPREADSHEET);
    FragmentManager fragmentManager = this.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    // Hide all the other fragments.
    this.hideAllOtherViewFragments(ViewFragmentType.SPREADSHEET, fragmentTransaction);
    // Try to retrieve one already there.
    SpreadsheetFragment spreadsheetFragment = (SpreadsheetFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.SPREADSHEET);
    if (spreadsheetFragment == null) {
        WebLogger.getLogger(getAppName()).d(TAG,
                "[showSpreadsheetFragment] no existing spreadshseet " + "fragment found");
    } else {
        WebLogger.getLogger(getAppName()).d(TAG,
                "[showSpreadsheetFragment] existing spreadsheet fragment " + "found");
    }
    WebLogger.getLogger(getAppName()).d(TAG, "[showSpreadsheetFragment] createNew is: " + createNew);
    if (spreadsheetFragment == null || createNew) {
        if (spreadsheetFragment != null) {
            WebLogger.getLogger(getAppName()).d(TAG, "[showSpreadsheetFragment] removing existing fragment");
            // Get rid of the existing fragment
            fragmentTransaction.remove(spreadsheetFragment);
        }
        spreadsheetFragment = this.createSpreadsheetFragment();
        fragmentTransaction.add(R.id.activity_table_display_activity_one_pane_content, spreadsheetFragment,
                Constants.FragmentTags.SPREADSHEET);
    } else {
        fragmentTransaction.show(spreadsheetFragment);
    }
    fragmentTransaction.commit();
}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

public void showListFragment(boolean createNew) {
    this.setCurrentFragmentType(ViewFragmentType.LIST);
    this.updateChildViewVisibility(ViewFragmentType.LIST);
    // Try to use a passed file name. If one doesn't exist, try to use the
    // default.//from w ww . ja v  a  2s.com
    String fileName = IntentUtil.retrieveFileNameFromBundle(this.getIntent().getExtras());
    if (fileName == null) {
        SQLiteDatabase db = null;
        try {
            db = DatabaseFactory.get().getDatabase(this, getAppName());
            fileName = TableUtil.get().getListViewFilename(db, getTableId());
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }
    FragmentManager fragmentManager = this.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    this.hideAllOtherViewFragments(ViewFragmentType.LIST, fragmentTransaction);
    ListViewFragment listViewFragment = (ListViewFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.LIST);
    if (listViewFragment == null || createNew) {
        if (listViewFragment == null) {
            WebLogger.getLogger(getAppName()).d(TAG, "[showListFragment] existing list fragment not found");
        } else {
            // remove the old fragment
            WebLogger.getLogger(getAppName()).d(TAG, "[showListFragment] removing old list fragment");
            fragmentTransaction.remove(listViewFragment);
        }
        listViewFragment = this.createListViewFragment(fileName);
        fragmentTransaction.add(R.id.activity_table_display_activity_one_pane_content, listViewFragment,
                Constants.FragmentTags.LIST);
    } else {
        WebLogger.getLogger(getAppName()).d(TAG, "[showListFragment] existing list fragment found");
        fragmentTransaction.show(listViewFragment);
    }
    fragmentTransaction.commit();
}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

public void showDetailFragment(boolean createNew) {
    this.setCurrentFragmentType(ViewFragmentType.DETAIL);
    this.updateChildViewVisibility(ViewFragmentType.DETAIL);
    FragmentManager fragmentManager = this.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    this.hideAllOtherViewFragments(ViewFragmentType.DETAIL, fragmentTransaction);
    String fileName = IntentUtil.retrieveFileNameFromBundle(this.getIntent().getExtras());
    // Try and use the default.
    if (fileName == null) {
        WebLogger.getLogger(getAppName()).d(TAG, "[showDetailFragment] fileName not found in Intent");
        SQLiteDatabase db = null;//w w w.jav  a2s .  com
        try {
            db = DatabaseFactory.get().getDatabase(this, getAppName());
            fileName = TableUtil.get().getDetailViewFilename(db, getTableId());
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }
    String rowId = IntentUtil.retrieveRowIdFromBundle(this.getIntent().getExtras());
    // Try to retrieve one that already exists.
    DetailViewFragment detailViewFragment = (DetailViewFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.DETAIL_FRAGMENT);
    if (detailViewFragment == null || createNew) {
        if (detailViewFragment != null) {
            WebLogger.getLogger(getAppName()).d(TAG,
                    "[showDetailViewFragment] removing old detail view fragment");
            fragmentTransaction.remove(detailViewFragment);
        } else {
            WebLogger.getLogger(getAppName()).d(TAG,
                    "[showDetailViewFragment] no existing detail view fragment found");
        }
        detailViewFragment = this.createDetailViewFragment(fileName, rowId);

        fragmentTransaction.add(R.id.activity_table_display_activity_one_pane_content, detailViewFragment,
                Constants.FragmentTags.DETAIL_FRAGMENT);
    } else {
        WebLogger.getLogger(getAppName()).d(TAG,
                "[showDetailViewFragment] existing detail view fragment found");
        fragmentTransaction.show(detailViewFragment);
    }

    fragmentTransaction.commit();
}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

public void showMapFragment(boolean createNew) {
    this.setCurrentFragmentType(ViewFragmentType.MAP);
    this.updateChildViewVisibility(ViewFragmentType.MAP);
    // Set the list view file name.
    String fileName = IntentUtil.retrieveFileNameFromBundle(this.getIntent().getExtras());
    if (fileName == null) {
        SQLiteDatabase db = null;/*from   w w w.  j  a  va 2  s.c o m*/
        try {
            db = DatabaseFactory.get().getDatabase(this, getAppName());
            fileName = TableUtil.get().getMapListViewFilename(db, getTableId());
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }
    FragmentManager fragmentManager = this.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    this.hideAllOtherViewFragments(ViewFragmentType.MAP, fragmentTransaction);
    MapListViewFragment mapListViewFragment = (MapListViewFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.MAP_LIST);
    TableMapInnerFragment innerMapFragment = (TableMapInnerFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.MAP_INNER_MAP);
    if (mapListViewFragment == null || (fileName != null && !fileName.equals(mapListViewFragment.getFileName()))
            || createNew) {
        if (mapListViewFragment != null) {
            // remove the old fragment
            WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] removing old map list fragment");
            fragmentTransaction.remove(mapListViewFragment);
        }
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] creating new map list fragment");
        mapListViewFragment = this.createMapListViewFragment(fileName);
        fragmentTransaction.add(R.id.map_view_list, mapListViewFragment, Constants.FragmentTags.MAP_LIST);
    } else {
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] existing map list fragment found");
        fragmentTransaction.show(mapListViewFragment);
    }
    if (innerMapFragment == null || createNew) {
        if (innerMapFragment != null) {
            // remove the old fragment
            WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] removing old inner map fragment");
            fragmentTransaction.remove(innerMapFragment);
        }
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] creating new inner map fragment");
        innerMapFragment = this.createInnerMapFragment();
        fragmentTransaction.add(R.id.map_view_inner_map, innerMapFragment,
                Constants.FragmentTags.MAP_INNER_MAP);
        innerMapFragment.listener = this;
    } else {
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] existing inner map fragment found");
        innerMapFragment.listener = this;
        fragmentTransaction.show(innerMapFragment);
    }
    fragmentTransaction.commit();
}

From source file:com.melbournestore.activities.MainActivity.java

private void selectItem(int position) {

    FragmentManager fragmentManager = getFragmentManager();
    // update the main content by replacing fragments
    switch (position) {
    case 0://  ww  w. jav a  2 s .  c o  m
        // mDrawerList.setItemChecked(position, true);
        // setTitle(mMenuTitles[position]);

        // Not logged in yet
        if (mUser.getPhoneNumber().equals("")) {
            Intent intent = new Intent(this, SignUpActivity.class);
            startActivityForResult(intent, LOGIN_CODE);
        } else {
            Intent intent = new Intent(this, MyAccountActivity.class);
            intent.putExtra("user", gson.toJson(mUser));
            intent.putExtra("order_num", mOrderNum);
            intent.putExtra("coupon_num", mCouponNum);
            startActivityForResult(intent, MY_ACCOUNT_CODE);
        }

        mDrawerLayout.closeDrawer(mDrawerList);
        break;

    case 1:

        // Fragment plate_fragment = new PlateFragment(this);

        fragmentManager.beginTransaction().replace(R.id.content_frame, plate_fragment).commit();

        // update selected myorder_list_item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        setTitle(mMenuTitles[position - 1]);
        mDrawerLayout.closeDrawer(mDrawerList);
        break;
    case 2:

        // Fragment myorders_fragment = new MyOrdersFragment();
        if (mUser.getPhoneNumber().equals("")) {
            Intent intent = new Intent(MainActivity.this, SignUpActivity.class);
            startActivity(intent);
        } else {
            fragmentManager.beginTransaction().replace(R.id.content_frame, myorders_fragment).commit();

            // update selected myorder_list_item and title, then close the drawer
            mDrawerList.setItemChecked(position, true);
            setTitle(mMenuTitles[position - 1]);
            mDrawerLayout.closeDrawer(mDrawerList);
        }
        break;
    case 3:

        // Fragment googlemap_fragment = new GoogleMapFragment(this);
        fragmentManager.beginTransaction().replace(R.id.content_frame, googlemap_fragment).commit();

        mDrawerList.setItemChecked(position, true);
        setTitle(mMenuTitles[position - 1]);
        mDrawerLayout.closeDrawer(mDrawerList);
        break;
    case 4:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Coming soon!").setCancelable(false).setPositiveButton("?",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        //do things
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
        //                mDrawerList.setItemChecked(position, true);
        //                setTitle(mMenuTitles[position - 1]);
        //                mDrawerLayout.closeDrawer(mDrawerList);
        break;
    case 5:
        fragmentManager.beginTransaction().replace(R.id.content_frame, recommandation_fragment).commit();
        mDrawerList.setItemChecked(position, true);
        setTitle(mMenuTitles[position - 1]);
        mDrawerLayout.closeDrawer(mDrawerList);
        break;
    }

}

From source file:com.zologic.tardis.app.MainActivity.java

private void restoreRetainedDataFragment() {
    // find the retained fragment
    FragmentManager fm = getFragmentManager();
    mRetainedDataFragment = (DataFragment) fm.findFragmentByTag(TAG);

    if (mRetainedDataFragment == null) {
        // Create
        mRetainedDataFragment = new DataFragment();
        fm.beginTransaction().add(mRetainedDataFragment, TAG).commitAllowingStateLoss(); // http://stackoverflow.com/questions/7575921/illegalstateexception-can-not-perform-this-action-after-onsaveinstancestate-h

        mScannedDevices = new ArrayList<>();

    } else {//from   w  w  w .  jav  a  2s  . com
        // Restore status
        mScannedDevices = mRetainedDataFragment.mScannedDevices;
        mComponentToStartWhenConnected = mRetainedDataFragment.mComponentToStartWhenConnected;
        mShouldEnableWifiOnQuit = mRetainedDataFragment.mShouldEnableWifiOnQuit;
        mFirmwareUpdater = mRetainedDataFragment.mFirmwareUpdater;
        mLatestCheckedDeviceAddress = mRetainedDataFragment.mLatestCheckedDeviceAddress;
        mSelectedDeviceData = mRetainedDataFragment.mSelectedDeviceData;

        if (mFirmwareUpdater != null) {
            mFirmwareUpdater.changedParentActivity(this); // set the new activity
        }
    }
}

From source file:com.example.nachiketvatkar.locateus.BluetoothPairing.java

private void restoreRetainedDataFragment() {
    // find the retained fragment
    FragmentManager fm = getFragmentManager();
    mRetainedDataFragment = (DataFragment) fm.findFragmentByTag(TAG);

    if (mRetainedDataFragment == null) {
        // Create
        mRetainedDataFragment = new DataFragment();
        fm.beginTransaction().add(mRetainedDataFragment, TAG).commitAllowingStateLoss(); // http://stackoverflow.com/questions/7575921/illegalstateexception-can-not-perform-this-action-after-onsaveinstancestate-h

        mScannedDevices = new ArrayList<>();

    } else {/*w w  w  . j  a v a 2  s.  co  m*/
        // Restore status
        mScannedDevices = mRetainedDataFragment.mScannedDevices;
        mComponentToStartWhenConnected = mRetainedDataFragment.mComponentToStartWhenConnected;
        mShouldEnableWifiOnQuit = mRetainedDataFragment.mShouldEnableWifiOnQuit;
        //            mFirmwareUpdater = mRetainedDataFragment.mFirmwareUpdater;
        mLatestCheckedDeviceAddress = mRetainedDataFragment.mLatestCheckedDeviceAddress;
        mSelectedDeviceData = mRetainedDataFragment.mSelectedDeviceData;

        //            if (mFirmwareUpdater != null) {
        //                mFirmwareUpdater.changedParentActivity(this);       // set the new activity
        //            }
    }
}

From source file:com.android.calendar.AllInOneActivity.java

@Override
public void handleEvent(EventInfo event) {
    long displayTime = -1;
    if (event.eventType == EventType.GO_TO) {
        if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) {
            mBackToPreviousView = true;//from   w  w w  .j a v  a 2 s.  co m
        } else if (event.viewType != mController.getPreviousViewType() && event.viewType != ViewType.EDIT) {
            // Clear the flag is change to a different view type
            mBackToPreviousView = false;
        }

        setMainPane(null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
        if (mSearchView != null) {
            mSearchView.clearFocus();
        }
        if (mShowCalendarControls) {
            int animationSize = (mOrientation == Configuration.ORIENTATION_LANDSCAPE) ? mControlsAnimateWidth
                    : mControlsAnimateHeight;
            boolean noControlsView = event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA;
            if (mControlsMenu != null) {
                mControlsMenu.setVisible(!noControlsView);
                mControlsMenu.setEnabled(!noControlsView);
            }
            if (noControlsView || mHideControls) {
                // hide minimonth and calendar frag
                mShowSideViews = false;
                if (!mHideControls) {
                    final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", 0,
                            animationSize);
                    slideAnimation.addListener(mSlideAnimationDoneListener);
                    slideAnimation.setDuration(mCalendarControlsAnimationTime);
                    ObjectAnimator.setFrameDelay(0);
                    slideAnimation.start();
                } else {
                    mMiniMonth.setVisibility(View.GONE);
                    mCalendarsList.setVisibility(View.GONE);
                    mMiniMonthContainer.setVisibility(View.GONE);
                }
            } else {
                // show minimonth and calendar frag
                mShowSideViews = true;
                mMiniMonth.setVisibility(View.VISIBLE);
                mCalendarsList.setVisibility(View.VISIBLE);
                mMiniMonthContainer.setVisibility(View.VISIBLE);
                if (!mHideControls && (mController.getPreviousViewType() == ViewType.MONTH
                        || mController.getPreviousViewType() == ViewType.AGENDA)) {
                    final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
                            animationSize, 0);
                    slideAnimation.setDuration(mCalendarControlsAnimationTime);
                    ObjectAnimator.setFrameDelay(0);
                    slideAnimation.start();
                }
            }
        }
        displayTime = event.selectedTime != null ? event.selectedTime.toMillis(true)
                : event.startTime.toMillis(true);
        if (!mIsTabletConfig) {
            refreshActionbarTitle(displayTime);
        }
    } else if (event.eventType == EventType.VIEW_EVENT) {

        // If in Agenda view and "show_event_details_with_agenda" is "true",
        // do not create the event info fragment here, it will be created by the Agenda
        // fragment

        if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
            if (event.startTime != null && event.endTime != null) {
                // Event is all day , adjust the goto time to local time
                if (event.isAllDay()) {
                    Utils.convertAlldayUtcToLocal(event.startTime, event.startTime.toMillis(false), mTimeZone);
                    Utils.convertAlldayUtcToLocal(event.endTime, event.endTime.toMillis(false), mTimeZone);
                }
                mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime, event.selectedTime,
                        event.id, ViewType.AGENDA, CalendarController.EXTRA_GOTO_TIME, null, null);
            } else if (event.selectedTime != null) {
                mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, event.id,
                        ViewType.AGENDA);
            }
        } else {
            // TODO Fix the temp hack below: && mCurrentView !=
            // ViewType.AGENDA
            if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
                mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, -1,
                        ViewType.CURRENT);
            }
            int response = event.getResponse();
            if ((mCurrentView == ViewType.AGENDA && mShowEventInfoFullScreenAgenda)
                    || ((mCurrentView == ViewType.DAY || (mCurrentView == ViewType.WEEK)
                            || mCurrentView == ViewType.MONTH) && mShowEventInfoFullScreen)) {
                // start event info as activity
                Intent intent = new Intent(Intent.ACTION_VIEW);
                Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
                intent.setData(eventUri);
                intent.setClass(this, EventInfoActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
                intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
                intent.putExtra(ATTENDEE_STATUS, response);
                startActivity(intent);
            } else {
                // start event info as a dialog
                EventInfoFragment fragment = new EventInfoFragment(this, event.id,
                        event.startTime.toMillis(false), event.endTime.toMillis(false), response, true,
                        EventInfoFragment.DIALOG_WINDOW_STYLE, null /* No reminders to explicitly pass in. */);
                fragment.setDialogParams(event.x, event.y, mActionBar.getHeight());
                FragmentManager fm = getFragmentManager();
                FragmentTransaction ft = fm.beginTransaction();
                // if we have an old popup replace it
                Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
                if (fOld != null && fOld.isAdded()) {
                    ft.remove(fOld);
                }
                ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
                ft.commit();
            }
        }
        displayTime = event.startTime.toMillis(true);
    } else if (event.eventType == EventType.UPDATE_TITLE) {
        setTitleInActionBar(event);
        if (!mIsTabletConfig) {
            refreshActionbarTitle(mController.getTime());
        }
    }
    updateSecondaryTitleFields(displayTime);
}

From source file:com.luan.thermospy.android.activities.MainActivity.java

@Override
public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments

    onSectionAttached(position);//from  w  ww . j  a  v  a2  s .  c  om
    FragmentManager fragmentManager = getFragmentManager();
    final ServerSettings serverSettings = Coordinator.getInstance().getServerSettings();
    final AlarmSettings alarmSettings = Coordinator.getInstance().getAlarmSettings();
    final String temperature = Coordinator.getInstance().getTemperature();

    final String ip = serverSettings.getIpAddress();
    final int port = serverSettings.getPort();

    final boolean isAlarmSwitchChecked = alarmSettings.isAlarmSwitchEnabled();
    final AlarmCondition condition = alarmSettings.getAlarmCondition();
    final String alarm = alarmSettings.getAlarm();

    FragmentTransaction transaction;
    if (position == 0) {

        if (ip.isEmpty() == false && port != -1) {
            Fragment fragment;
            if (isAlarmSwitchChecked) {
                fragment = MonitorFragment.newInstance(ip, port, alarm, temperature);
            } else {
                fragment = MonitorFragment.newInstance(ip, port, getString(R.string.not_enabled), temperature);
            }
            transaction = fragmentManager.beginTransaction().replace(R.id.container, fragment);
        } else {
            // No ip or port available. Show server setup fragment
            transaction = fragmentManager.beginTransaction().replace(R.id.container,
                    SetupService.newInstance(ip, port));

        }
    } else if (position == 1) {
        FragmentTransaction ft = fragmentManager.beginTransaction();
        transaction = ft.replace(R.id.container, Alarm.newInstance(alarm, isAlarmSwitchChecked,
                Coordinator.getInstance().getServerSettings(), condition));
    } else if (position == 2) {
        transaction = fragmentManager.beginTransaction().replace(R.id.container,
                SetupService.newInstance(ip, port));
    } else if (position == 3) {
        Intent intent = new Intent(this, LogSessionActivity.class);
        startActivity(intent);
        return;
    } else {
        transaction = fragmentManager.beginTransaction();
    }

    mLastSelected = position;
    transaction.commit();
}