Example usage for android.support.v4.app FragmentManager beginTransaction

List of usage examples for android.support.v4.app FragmentManager beginTransaction

Introduction

In this page you can find the example usage for android.support.v4.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.conferenceengineer.android.iosched.ui.SearchActivity.java

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

    setContentView(R.layout.activity_search);
    mTwoPane = (findViewById(R.id.fragment_container_detail) != null);

    FragmentManager fm = getSupportFragmentManager();
    mSessionsFragment = (SessionsFragment) fm.findFragmentById(R.id.fragment_container_master);
    if (mSessionsFragment == null) {
        mSessionsFragment = new SessionsFragment();
        fm.beginTransaction().add(R.id.fragment_container_master, mSessionsFragment).commit();
    }/*from w w w.  j a  v  a 2  s . co  m*/

    mDetailFragment = fm.findFragmentById(R.id.fragment_container_detail);

    mImageLoader = new ImageLoader(this, R.drawable.person_image_empty)
            .setMaxImageSize(getResources().getDimensionPixelSize(R.dimen.speaker_image_size))
            .setFadeInImage(UIUtils.hasHoneycombMR1());
}

From source file:com.cypress.cysmart.CommonFragments.NavigationDrawerFragment.java

/**
 * Used for replacing the main content of the view with provided fragments
 *
 * @param fragment//from w  ww.j av a2s. c o m
 */
void displayView(Fragment fragment) {
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.container, fragment).addToBackStack(null).commit();
}

From source file:com.darizotas.metadatastrip.FileListActivity.java

/**
 * Callback method from {@link FileListFragment.Callbacks} indicating that
 * the item with the given PATH was selected.
 *///from  w  w w .j a  va2 s. co m
@Override
public void onItemSelected(String path) {
    File file = new File(path);
    if (file.canRead()) {
        if (file.isDirectory()) {
            FragmentManager manager = getSupportFragmentManager();

            if (mTwoPane) {
                // Removes the previous detail fragment
                Fragment fragment = manager.findFragmentById(R.id.file_detail_container);
                if (fragment != null) {
                    manager.beginTransaction().remove(fragment).commit();
                    //http://stackoverflow.com/questions/7246479/android-fragmenttransaction-commit-when
                    manager.executePendingTransactions();
                }
            }
            // Updates the list.
            ((FileListFragment) manager.findFragmentById(R.id.file_list)).updateListAdapter(file.getPath());

        } else {
            showDetails(path);
        }
        // The folder cannot be read.
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setIcon(R.drawable.ic_launcher)
                .setTitle("[" + file.getName() + "] " + getResources().getText(R.string.error_open_file))
                .setPositiveButton("OK", null).show();
    }
}

From source file:com.derdoktor667.dev.thematrix.TheMainActivity.java

private void showFragment(int fragmentIndex) {
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction transaction = fm.beginTransaction();

    for (int i = 0; i < fragments.length; i++) {
        if (i == fragmentIndex) {
            transaction.show(fragments[i]);
        } else {/* w ww .j  a va  2s.  c  om*/
            transaction.hide(fragments[i]);
        }
    }
    transaction.commit();
}

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

public void updateContent(int state) {
    ModelFragment fragment = null;/*from   www.j  a  va  2 s  .  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.alivenet.dmvtaxi.fragment.Fragment_ride_list.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_ride_list, container, false);
    mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE);
    mUserId = mPref.getString("userId", null);

    progressDialog = new ProgressDialog(getActivity());
    progressDialog.setMessage("Please wait...");
    progressDialog.setCancelable(false);

    recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    recyclerView.setHasFixedSize(true);/*from  w  w  w. j a  v  a  2  s.  c om*/
    LinearLayoutManager llm = new LinearLayoutManager(getActivity());
    llm.setOrientation(LinearLayoutManager.VERTICAL);

    recyclerView.addItemDecoration(new SpacesItemDecoration(VERTICAL_ITEM_SPACE));

    recyclerView.setLayoutManager(llm);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    mnorides = (TextView) view.findViewById(R.id.tv_norides);
    RequestParams params = new RequestParams();
    params.put("userId", mUserId);
    rideListWs(params);

    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                // handle back button's click listener

                if (keyCode == KeyEvent.KEYCODE_BACK) {

                    Fragment homeFragment = new FragmentMainScreen();
                    FragmentManager frgManager;
                    frgManager = getFragmentManager();
                    frgManager.beginTransaction().replace(R.id.fragment_switch, homeFragment).commit();

                    return true;
                }

                return true;
            }
            return false;
        }
    });

    return view;
}

From source file:com.digi.android.wva.FaultCodeActivity.java

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

    setContentView(R.layout.fault_code_activity);
    ActionBar ab = getSupportActionBar();
    ab.setDisplayHomeAsUpEnabled(true);//from  w w w.  ja  va2  s. com
    ab.setTitle("Fault Code Browser");

    // Figure out if the layout has space for two fragments.
    twoColumns = (findViewById(R.id.faultCodeDetailFragment) != null);

    FragmentManager fm = getSupportFragmentManager();

    // FaultCodeBrowsingFragment uses setRetainInstance, so that a single fragment instance
    // can persist between configuration changes (e.g. screen rotation)
    if (fm.findFragmentByTag(BROWSE_FRAG_TAG) == null) { // Fresh instance of the activity
        FragmentTransaction transaction = fm.beginTransaction();
        transaction.replace(R.id.faultCodeFragment, new FaultCodeBrowsingFragment(), BROWSE_FRAG_TAG);
        transaction.commit();
    }
}

From source file:ch.corten.aha.worldclock.EditClockActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getSupportActionBar();
    LayoutInflater inflator = (LayoutInflater) actionBar.getThemedContext()
            .getSystemService(LAYOUT_INFLATER_SERVICE);
    View customActionBarView = inflator.inflate(R.layout.actionbar_custom_view_done_discard, null);
    customActionBarView.findViewById(R.id.actionbar_discard).setOnClickListener(new View.OnClickListener() {
        @Override// www .  j  a  va  2s. c o m
        public void onClick(View v) {
            finish();
        }
    });
    customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getFragment().done();
        }
    });

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME);
    actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    FragmentManager fm = getSupportFragmentManager();
    // Create the list fragment and add it as our sole content.
    if (fm.findFragmentById(android.R.id.content) == null) {
        EditClockFragment fragment = new EditClockFragment();
        fm.beginTransaction().add(android.R.id.content, fragment).commit();
    }
}

From source file:ch.berta.fabio.popularmovies.presentation.ui.fragments.MovieDetailsFavFragment.java

@Override
public void loadUpdateMovieDetailsWorker(int movieDbId, long movieRowId) {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment worker = WorkerUtils.findWorker(fragmentManager, UpdateMovieDetailsWorker.WORKER_TAG);

    if (worker == null) {
        worker = UpdateMovieDetailsWorker.newInstance(movieDbId, movieRowId);
        fragmentManager.beginTransaction().add(worker, UpdateMovieDetailsWorker.WORKER_TAG).commit();
    }/*from  w w w .  j  a  v  a2  s. c om*/
}

From source file:click.kobaken.rxirohaandroid_sample.view.activity.MainActivity.java

private void switchFragment(@NonNull Fragment fragment, String tag) {
    if (fragment.isAdded()) {
        return;//from  w w w .  j av a2 s .c o m
    }

    final FragmentManager manager = getSupportFragmentManager();
    final FragmentTransaction fragmentTransaction = manager.beginTransaction();

    final Fragment currentFragment = manager.findFragmentById(R.id.container);
    if (currentFragment != null) {
        fragmentTransaction.detach(currentFragment);
    }

    if (fragment.isDetached()) {
        fragmentTransaction.attach(fragment);
    } else {
        fragmentTransaction.add(R.id.container, fragment, tag);
    }
    fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit();
}