Example usage for android.app FragmentTransaction replace

List of usage examples for android.app FragmentTransaction replace

Introduction

In this page you can find the example usage for android.app FragmentTransaction replace.

Prototype

public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment);

Source Link

Document

Calls #replace(int,Fragment,String) with a null tag.

Usage

From source file:com.android.tv.settings.accessories.AddAccessoryActivity.java

protected void switchToMultipleDevicesFragment() {
    FragmentTransaction ft = mFragmentManager.beginTransaction();
    mContentFragment = AddAccessoryContentFragment.newInstance(true);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.replace(R.id.content_fragment, mContentFragment);
    ft.disallowAddToBackStack();//from   w  w  w  .jav  a 2 s.  co  m

    ft.commit();
    mMsgHandler.sendEmptyMessageDelayed(MSG_MULTIPAIR_BLINK, BLINK_START);
    mShowingMultiFragment = true;
}

From source file:com.benlinskey.greekreference.MainActivity.java

/**
 * Displays the specified lexicon entry in a {@link LexiconDetailFragment}.
 * @param id the lexicon database ID of the selected entry
 * @param word the word whose entry is selected
 * @param entry the selected entry's XML
 *//*  w  w  w  .  ja  va  2 s.  c  o m*/
void displayLexiconEntry(final String id, String word, String entry) {
    // If user searches from Quick Search Box, we may need to change mode.
    if (!mMode.equals(Mode.LEXICON_BROWSE) && !mMode.equals(Mode.LEXICON_FAVORITES)
            && !mMode.equals(Mode.LEXICON_HISTORY)) {
        switchToLexiconBrowse();
    }

    // Add entry to history, unless word was selected from history list.
    if (!mMode.equals(Mode.LEXICON_HISTORY)) {
        addHistory(id, word);
    }

    // Display entry.
    if (mTwoPane) {
        Bundle arguments = new Bundle();
        arguments.putString(LexiconDetailFragment.ARG_ENTRY, entry);
        LexiconDetailFragment fragment = new LexiconDetailFragment();
        fragment.setArguments(arguments);
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.item_detail_container, fragment);
        transaction.commitAllowingStateLoss();
    } else {
        LexiconListFragment fragment = (LexiconListFragment) getFragmentManager()
                .findFragmentById(R.id.item_list_container);
        int lexiconId = fragment.getSelectedLexiconId();

        Intent intent = new Intent(this, LexiconDetailActivity.class);
        intent.putExtra(LexiconDetailFragment.ARG_ENTRY, entry);
        intent.putExtra(LexiconDetailActivity.ARG_LEXICON_ID, lexiconId);
        intent.putExtra(LexiconDetailActivity.ARG_WORD, word);
        startActivity(intent);
    }
}

From source file:org.taulabs.androidgcs.ObjectManagerActivity.java

private void selectItem(int position) {

    NavDrawerItem selectedItem = navConf.getNavItems()[position];

    // Selected item indicates an activity to launch
    if (selectedItem.getType() == NavMenuActivity.ACTIVITY_TYPE) {
        NavMenuActivity launcherItem = (NavMenuActivity) selectedItem;
        if (launcherItem.getLaunchClass() != null) {
            Log.d(TAG,/*w  w  w .ja v  a2s.c o  m*/
                    "ID: " + selectedItem.getId() + " " + selectedItem.getLabel() + " position: " + position);

            mDrawerList.setItemChecked(position, true);

            if (selectedItem.updateActionBarTitle()) {
                setTitle(selectedItem.getLabel());
            }

            if (this.mDrawerLayout.isDrawerOpen(this.mDrawerList)) {
                mDrawerLayout.closeDrawer(mDrawerList);
            }

            startActivity(new Intent(this, launcherItem.getLaunchClass()));
        }

        return;
    }

    // Selected item indicates the contents to put in the main frame
    if (selectedItem.getType() == NavMenuItem.ITEM_TYPE) {

        if (findViewById(navConf.getMainLayout()) == null) {
            // If not the new main activity should be activated.

            // Close drawer first
            mDrawerList.setItemChecked(position, true);
            if (this.mDrawerLayout.isDrawerOpen(this.mDrawerList)) {
                mDrawerLayout.closeDrawer(mDrawerList);
            }

            // Activate main activity, indicating the fragment it should show 
            Intent mainScreen = new Intent(this, MainActivity.class);
            mainScreen.putExtra("ContentFrag", selectedItem.getId());
            startActivity(mainScreen);

            return;
        } else {

            int id = (int) selectedItem.getId();
            FragmentTransaction trans = getFragmentManager().beginTransaction();
            trans.replace(navConf.getMainLayout(), getFragmentById(id));
            trans.commit();

            mDrawerList.setItemChecked(position, true);

            if (selectedItem.updateActionBarTitle()) {
                Log.d(TAG, "Selected item title: " + selectedItem.getLabel());
                setTitle(selectedItem.getLabel());
            }

            if (this.mDrawerLayout.isDrawerOpen(this.mDrawerList)) {
                mDrawerLayout.closeDrawer(mDrawerList);
            }
        }
    }

}

From source file:com.dsna.android.main.MainActivity.java

private void openFragment(BaseFragment baseFragment) {
    if (baseFragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        fragmentTransaction.replace(R.id.fragment_main, baseFragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();/*from   ww w  .ja  v a 2s.com*/
        if (baseFragment.getTitleResourceId() > 0)
            mCurrentTitle = baseFragment.getTitleResourceId();

    }
}

From source file:com.dvn.vindecoder.ui.seller.GetAllVehicalSellerDetails.java

void addFragmentToStack() {
    mStackLevel++;/*from   w w  w  . java  2  s .  c o m*/

    // Instantiate a new fragment.
    Fragment newFragment = GetNewVehicalFragment.newInstance(GetAllVehicalSellerDetails.this);

    // Add the fragment to the activity, pushing this transaction
    // on to the back stack.
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
            R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
    ft.replace(R.id.fragment1, newFragment);
    // ft.addToBackStack(null);
    ft.commit();
}

From source file:org.ozonecity.gpslogger2.GpsMainActivity.java

private void LoadFragmentView(int position) {
    FragmentTransaction transaction = getFragmentManager().beginTransaction();

    switch (position) {
    case 0:/*w  ww.  j a  v  a  2  s  .  c  om*/
        transaction.replace(R.id.container, GpsSimpleViewFragment.newInstance());
        break;
    case 1:
        transaction.replace(R.id.container, GpsDetailedViewFragment.newInstance());
        break;
    default:
    case 2:
        transaction.replace(R.id.container, GpsBigViewFragment.newInstance());
        break;
    }
    transaction.commitAllowingStateLoss();
}

From source file:dev.dworks.apps.anexplorer.fragment.DirectoryFragment.java

private static void show(FragmentManager fm, int type, RootInfo root, DocumentInfo doc, String query,
        int anim) {
    final Bundle args = new Bundle();
    args.putInt(EXTRA_TYPE, type);/*from   w  w w . ja va2 s . c om*/
    args.putParcelable(EXTRA_ROOT, root);
    args.putParcelable(EXTRA_DOC, doc);
    args.putString(EXTRA_QUERY, query);

    final FragmentTransaction ft = fm.beginTransaction();
    switch (anim) {
    case ANIM_SIDE:
        args.putBoolean(EXTRA_IGNORE_STATE, true);
        break;
    case ANIM_DOWN:
        args.putBoolean(EXTRA_IGNORE_STATE, true);
        ft.setCustomAnimations(R.animator.dir_down, R.animator.dir_frozen);
        break;
    case ANIM_UP:
        ft.setCustomAnimations(R.animator.dir_frozen, R.animator.dir_up);
        break;
    }

    final DirectoryFragment fragment = new DirectoryFragment();
    fragment.setArguments(args);

    ft.replace(R.id.container_directory, fragment);
    ft.commitAllowingStateLoss();
}

From source file:fr.cph.chicago.activity.MainActivity.java

@Override
public final void onNavigationDrawerItemSelected(final int position) {
    int oldPosition = mCurrentPosition;
    mCurrentPosition = position;//from  w ww .ja  va  2 s  .  c  o  m
    // update the main content by replacing fragments
    final FragmentManager fragmentManager = getFragmentManager();
    final FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    switch (position) {
    case POSITION_FAVORITES:
        if (mFavoritesFragment == null) {
            mFavoritesFragment = FavoritesFragment.newInstance(position + 1);
        }
        if (!this.isFinishing()) {
            ft.replace(R.id.container, mFavoritesFragment).commit();
        }
        break;
    case POSITION_TRAIN:
        if (mTrainFragment == null) {
            mTrainFragment = TrainFragment.newInstance(position + 1);
        }
        if (!this.isFinishing()) {
            ft.replace(R.id.container, mTrainFragment).commit();
        }
        break;
    case POSITION_BUS:
        if (mBusFragment == null) {
            mBusFragment = BusFragment.newInstance(position + 1);
        }
        if (!this.isFinishing()) {
            ft.replace(R.id.container, mBusFragment).commit();
        }
        break;
    case POSITION_DIVVY:
        if (mBikeFragment == null) {
            mBikeFragment = BikeFragment.newInstance(position + 1);
        }
        if (!this.isFinishing()) {
            ft.replace(R.id.container, mBikeFragment).commit();
        }
        break;
    case POSITION_NEARBY:
        if (mNearbyFragment == null) {
            mNearbyFragment = NearbyFragment.newInstance(position + 1);
            if (!this.isFinishing()) {
                ft.replace(R.id.container, mNearbyFragment).commit();
            }
        } else {
            if (oldPosition == 4) {
                fragmentManager.beginTransaction().commit();
            } else {
                if (!this.isFinishing()) {
                    ft.replace(R.id.container, mNearbyFragment).commit();
                }
            }
        }
        break;
    case POSITION_ALERTS:
        if (mAlertFragment == null) {
            mAlertFragment = AlertFragment.newInstance(position + 1);
        }
        if (!this.isFinishing()) {
            ft.replace(R.id.container, mAlertFragment).commit();
        }
        break;
    case POSITION_MAP:
        if (mMapFragment == null) {
            mMapFragment = MapFragment.newInstance(position + 1);
        }
        if (!this.isFinishing()) {
            ft.replace(R.id.container, mMapFragment).commit();
        }
        break;
    case POSITION_SETTINGS:
        if (mSettingsFragment == null) {
            mSettingsFragment = SettingsFragment.newInstance(position + 1);
        }
        if (!this.isFinishing()) {
            ft.replace(R.id.container, mSettingsFragment).commit();
        }
        break;
    }
}

From source file:com.dvn.vindecoder.ui.seller.GetAllVehicalSellerDetails.java

@Override
public void onDataComplete(int i, String image_path) {
    if (i == 1) {
        Bitmap bitmap = ((BitmapDrawable) car_image.getDrawable()).getBitmap();
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
        File destination = new File(getCacheDir(), "car.jpg");
        FileOutputStream fo;/*  ww  w .  j  a  v  a 2 s .c  om*/
        try {
            fo = new FileOutputStream(destination);
            fo.write(bytes.toByteArray());
            fo.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        image_path = destination.getAbsolutePath();
        // car_image.setImageBitmap(bitmap);
        newFragment.setImagePath(image_path);
    } else if (i == 2) {
        /*car_image.setOnClickListener(null);
        car_image1.setOnClickListener(null);*/
        collapsingToolbarLayout.setVisibility(View.GONE);
        Fragment newFragment = UserAddNewVehicalSecond.newInstance(GetAllVehicalSellerDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        //  ft.addToBackStack(null);
        ft.commit();
    } else if (i == 3) {
        Fragment newFragment = UserAddNewVehicalThird.newInstance(GetAllVehicalSellerDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        // ft.addToBackStack(null);
        ft.commit();
    } else if (i == 4) {
        Fragment newFragment = UserNewVehicalFourth.newInstance(GetAllVehicalSellerDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        //   ft.addToBackStack(null);
        ft.commit();
    } else if (i == 5) {
        Fragment newFragment = UserAddNewVehicalFifth.newInstance(GetAllVehicalSellerDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        //  ft.addToBackStack(null);
        ft.commit();
    }

    else if (i == 0) {

        Glide.with(GetAllVehicalSellerDetails.this).load(image_path).asBitmap()
                .into(new SimpleTarget<Bitmap>(300, 300) {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
                        //setBackgroundImage(resource);
                        car_image.setImageBitmap(resource);
                        car_image1.setImageBitmap(resource);
                    }
                });
    }
}

From source file:com.cdhxqh.inventorymovement.ui.MainActivity.java

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
    mSelectPos = position;//from w  w  w .  ja v  a 2 s  .co m

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

    switch (position) {
    case 0://
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newItemFragment == null) {
            newItemFragment = new ItemFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newItemFragment.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newItemFragment).commit();
        drawer.closeDrawer(mDrawerList);
        break;
    case 1://?
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newPoFragemnt == null) {
            newPoFragemnt = new PoFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newPoFragemnt.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newPoFragemnt).commit();
        drawer.closeDrawer(mDrawerList);
        break;
    case 2://?
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newWorkorderFragment == null) {
            newWorkorderFragment = new WorkorderFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newWorkorderFragment.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newWorkorderFragment).commit();
        drawer.closeDrawer(mDrawerList);
        break;
    case 3://
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newCheckFragment == null) {
            newCheckFragment = new CheckFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newCheckFragment.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newCheckFragment).commit();
        drawer.closeDrawer(mDrawerList);
        break;
    case 4://
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newPoFragemnt == null) {
            newLocationFragment = new LocationFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newLocationFragment.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newLocationFragment).commit();
        drawer.closeDrawer(mDrawerList);
        break;
    //            case 5://???
    //                titleTextView.setText(adapter.getTitle(position));
    //                searchButton.setVisibility(View.GONE);
    //                if (newTypoFragment == null) {
    //                    newTypoFragment = new TypoFragment();
    //                    Bundle bundle = new Bundle();
    //                    bundle.putString("text", adapter.getTitle(position));
    //                    newTypoFragment.setArguments(bundle);
    //                }
    //                fragmentTransaction.replace(R.id.content_frame, newTypoFragment).commit();
    //                drawer.closeDrawer(mDrawerList);
    //                break;
    case 5://
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newInVFragment == null) {
            newInVFragment = new InVFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newInVFragment.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newInVFragment).commit();
        drawer.closeDrawer(mDrawerList);
        break;
    case 6://?
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newItemreqFragment == null) {
            newItemreqFragment = new ItemreqFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newItemreqFragment.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newItemreqFragment).commit();
        drawer.closeDrawer(mDrawerList);
        break;

    case 7: //
        showAlertDialog();
        searchButton.setVisibility(View.GONE);
        drawer.closeDrawer(mDrawerList);
        break;
    default:
        titleTextView.setText(adapter.getTitle(position));
        Fragment contentFragment = new ContentFragment();
        Bundle args = new Bundle();
        args.putString("text", adapter.getTitle(position));
        contentFragment.setArguments(args);

        fragmentTransaction.replace(R.id.content_frame, contentFragment).commit();

        drawer.closeDrawer(mDrawerList);
        break;
    }

}