Example usage for android.support.v4.app FragmentTransaction commit

List of usage examples for android.support.v4.app FragmentTransaction commit

Introduction

In this page you can find the example usage for android.support.v4.app FragmentTransaction commit.

Prototype

public abstract int commit();

Source Link

Document

Schedules a commit of this transaction.

Usage

From source file:br.liveo.ndrawer.ui.fragment.FragmentNotificationsfacebook.java

private void reloadfragment() {

    FragmentManager manager = getActivity().getSupportFragmentManager();
    FragmentTransaction ft = manager.beginTransaction();
    Fragment newFragment = this;
    this.onDestroy();
    ft.remove(this);
    ft.replace(R.id.container, newFragment);
    //container is the ViewGroup of current fragment
    ft.addToBackStack(null);/*w w  w . j a  v a  2 s  .  c  o m*/
    ft.commit();

}

From source file:au.com.wallaceit.reddinator.ViewRedditActivity.java

/**
 * (non-Javadoc)/* www .j a  v a 2 s.  c o  m*/
 *
 * @see android.widget.TabHost.OnTabChangeListener#onTabChanged(java.lang.String)
 */
public void onTabChanged(String tag) {
    TabInfo newTab = this.mapTabInfo.get(tag);
    if (mLastTab != newTab) {
        android.support.v4.app.FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
        if (mLastTab != null) {
            if (mLastTab.fragment != null) {
                ft.detach(mLastTab.fragment);
            }
        }
        if (newTab != null) {
            if (newTab.fragment == null) {
                newTab.fragment = Fragment.instantiate(this, newTab.clss.getName(), newTab.args);
                ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag);
            } else {
                ft.attach(newTab.fragment);
            }
        }

        mLastTab = newTab;
        ft.commit();
        this.getSupportFragmentManager().executePendingTransactions();
    }
}

From source file:com.ayuget.redface.ui.activity.TopicsActivity.java

/**
 * Loads a topic in the appropriate panel for a given page and position
 *///from w  w w  . j a  va  2 s  .co  m
protected void loadTopic(Topic topic, int page, PagePosition pagePosition) {
    Log.d(LOG_TAG, String.format("Loading topic '%s' (page %d)", topic.getSubject(), page));
    TopicFragment topicFragment = new TopicFragmentBuilder(page, topic).currentPagePosition(pagePosition)
            .build();

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    int topicFragmentContainer = isTwoPaneMode() ? R.id.details_container : R.id.container;

    if (!isTwoPaneMode()) {
        Log.d(LOG_TAG, "Setting slide animation for topicFragment");
        transaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left,
                R.anim.exit_to_right);
    }

    transaction.replace(topicFragmentContainer, topicFragment, TOPIC_FRAGMENT_TAG);
    transaction.addToBackStack(TOPIC_FRAGMENT_TAG);
    transaction.commit();
}

From source file:com.autoparts.buyers.activity.InquiryModelActivity.java

public void updateContent(int state) {
    ModelFragment fragment = null;/*w  w w  .j  a v a2s.c o  m*/
    String tag = "";
    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction tr = fm.beginTransaction();

    if (currentState != state) {
        final Fragment currentFragment = fm.findFragmentByTag(currentContentFragmentTag);
        if (currentFragment != null)
            tr.hide(currentFragment);
    }
    //        if (AboutFragment.ABOUT_URI.equals(uri)) {
    tag = ModelFragment.TAG;
    final ModelFragment foundFragment = (ModelFragment) fm.findFragmentByTag(tag);
    if (foundFragment != null) {
        fragment = foundFragment;
    } else {
        fragment = new ModelFragment(handlerSelected);
    }
    //        }

    if (fragment.isAdded()) {
        tr.show(fragment);
    } else {
        tr.replace(R.id.content, fragment, tag);
    }
    tr.commit();
    if (mList != null && state < mList.size()) {
        fragment.model_data(mList.get(state).getUser_id());
    }

    currentState = state;
    currentContentFragmentTag = tag;
}

From source file:com.android.cabapp.fragments.MyAccountFragment.java

@Override
public void onAttach(Activity activity) {
    // TODO Auto-generated method stub
    super.onAttach(activity);

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    // add MyFilter fragment
    myFiltersFragment = new MyFiltersFragment();
    fragmentTransaction.add(R.id.fragment_myFilters, myFiltersFragment);
    fragmentTransaction.commit();

    // if (myFiltersFragment != null)
    // myFiltersFragment.updateView();

}

From source file:com.bq.robotic.robopad.RoboPad.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_robopad);

    robotType robotTypeSelected = (robotType) getIntent()
            .getSerializableExtra(RoboPadConstants.ROBOT_SELECTED_KEY);

    mFragmentManager = getSupportFragmentManager();

    connectButton = (ImageButton) findViewById(R.id.connect_button);
    disconnectButton = (ImageButton) findViewById(R.id.disconnect_button);
    anim = AnimationUtils.loadAnimation(this, R.anim.bluetooth_spiner);

    // If we're being restored from a previous state,
    // then we don't need to do anything and should return or else
    // we could end up with overlapping fragments.
    if (savedInstanceState != null) {
        return;/* w  w  w.j a v a 2s.c  om*/
    }

    // Show the selected robot fragment
    FragmentTransaction ft = mFragmentManager.beginTransaction();
    switch (robotTypeSelected) {

    case POLLYWOG:
        ft.replace(R.id.game_pad_container, new PollywogFragment());
        break;

    case BEETLE:
        ft.replace(R.id.game_pad_container, new BeetleFragment());
        break;

    case EVOLUTION:
        ft.replace(R.id.game_pad_container, new EvolutionFragment());
        break;

    case RHINO:
        ft.replace(R.id.game_pad_container, new RhinoFragment());
        break;

    case CRAB:
        ft.replace(R.id.game_pad_container, new CrabFragment());
        break;

    case GENERIC_ROBOT:
        ft.replace(R.id.game_pad_container, new GenericRobotFragment());
        break;

    }

    ft.commit();

}

From source file:android.support.v17.leanback.app.DetailsSupportFragment.java

/**
 * This method asks DetailsSupportFragmentBackgroundController to add a fragment for rendering video.
 * In case the fragment is already there, it will return the existing one. The method must be
 * called after calling super.onCreate(). App usually does not call this method directly.
 *
 * @return Fragment the added or restored fragment responsible for rendering video.
 * @see DetailsSupportFragmentBackgroundController#onCreateVideoSupportFragment()
 *///w w w . j a  v  a 2 s . c  o  m
final Fragment findOrCreateVideoSupportFragment() {
    if (mVideoSupportFragment != null) {
        return mVideoSupportFragment;
    }
    Fragment fragment = getChildFragmentManager().findFragmentById(R.id.video_surface_container);
    if (fragment == null && mDetailsBackgroundController != null) {
        FragmentTransaction ft2 = getChildFragmentManager().beginTransaction();
        ft2.add(android.support.v17.leanback.R.id.video_surface_container,
                fragment = mDetailsBackgroundController.onCreateVideoSupportFragment());
        ft2.commit();
        if (mPendingFocusOnVideo) {
            // wait next cycle for Fragment view created so we can focus on it.
            // This is a bit hack eventually we will do commitNow() which get view immediately.
            getView().post(new Runnable() {
                @Override
                public void run() {
                    if (getView() != null) {
                        switchToVideo();
                    }
                    mPendingFocusOnVideo = false;
                }
            });
        }
    }
    mVideoSupportFragment = fragment;
    return mVideoSupportFragment;
}

From source file:com.akop.bach.activity.RibbonedMultiPane.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(getLayout());/*from  ww w.ja  v a  2s  .  co  m*/

    if ((mAccount = (BasicAccount) getIntent().getParcelableExtra("account")) == null && !allowNullAccounts()) {
        if (App.getConfig().logToConsole())
            App.logv("Account is null");

        finish();
        return;
    }

    if (android.os.Build.VERSION.SDK_INT >= 11) {
        new ActionBarHelper().init();
    }

    // this part was under each activity

    if (!initializeParameters()) {
        finish();
        return;
    }

    FragmentManager fm = getSupportFragmentManager();
    Fragment titleFrag;

    FragmentTransaction ft = fm.beginTransaction();
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

    if ((titleFrag = fm.findFragmentByTag("title")) == null) {
        titleFrag = instantiateTitleFragment();
        ft.replace(R.id.fragment_titles, titleFrag, "title");
    }

    if (isDualPane()) {
        if ((mDetailFragment = fm.findFragmentByTag("details")) == null) {
            if ((mDetailFragment = instantiateDetailFragment()) != null)
                ft.replace(R.id.fragment_details, mDetailFragment, "details");
        } else if (mDetailFragment.isDetached()) {
            ft.attach(mDetailFragment);
        }
    } else {
        Fragment detailFragment;
        if ((detailFragment = fm.findFragmentByTag("details")) != null) {
            ft.detach(detailFragment);
        }
    }

    ft.commit();
}

From source file:com.binary_machinery.avalonschedule.view.schedule.SchedulePageFragment.java

@Nullable
@Override/*from   w w  w.  j av a 2s.  c o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.schedule_page, container, false);
    Bundle arguments = getArguments();

    FragmentManager fragmentManager = getChildFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    Func2<Integer, Integer, ?> setRecord = (dayOfWeek, layoutId) -> {
        String key = ARG_DAY + dayOfWeek;
        ScheduleRecord record = arguments.getParcelable(key);

        if (record != null) {
            Fragment fragment = (record.course != null) ? new RecordFragment() : new EmptyRecordFragment();
            Bundle args = new Bundle();
            args.putParcelable(RecordFragment.ARG_RECORD, record);
            fragment.setArguments(args);
            fragmentTransaction.replace(layoutId, fragment);
        }

        return 0;
    };

    setRecord.call(Calendar.MONDAY, R.id.layoutMonday);
    setRecord.call(Calendar.TUESDAY, R.id.layoutTuesday);
    setRecord.call(Calendar.WEDNESDAY, R.id.layoutWednesday);
    setRecord.call(Calendar.THURSDAY, R.id.layoutThursday);
    setRecord.call(Calendar.FRIDAY, R.id.layoutFriday);
    setRecord.call(Calendar.SATURDAY, R.id.layoutSaturday);
    setRecord.call(Calendar.SUNDAY, R.id.layoutSunday);

    fragmentTransaction.commit();
    return rootView;
}

From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java

private LibraryFragment initializeLibraryFragment() {
    LibraryFragment fragment = (LibraryFragment) mFragmentManager.findFragmentByTag(FRAGMENT_TAG_LIBRARY);

    if (fragment == null) {
        fragment = new LibraryFragment();
        final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.replace(R.id.library_root_frame, fragment, FRAGMENT_TAG_LIBRARY);
        ft.commit();
    }/*www .ja  va2 s.c o m*/

    return fragment;
}