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

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

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

@Override
public void pushLibraryFragment(final Fragment fragment, final String label) {
    final String title;
    if (fragment instanceof BrowseFragment) {
        title = ((BrowseFragment) fragment).getTitle();
    } else {//from  w  ww .j  a  va  2 s  . c  o m
        title = fragment.toString();
    }
    final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.replace(R.id.library_root_frame, fragment);
    ft.addToBackStack(label);
    ft.setBreadCrumbTitle(title);
    ft.commit();
}

From source file:com.example.angel.parkpanda.MainActivity.java

public void doPrevAction(String strClass) {

    if (strClass.contains("change_password")) {
        Fragment fragment = new my_account();
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction FT = fragmentManager.beginTransaction();
        FT.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right);
        FT.replace(R.id.flContent, fragment).commit();
    }//from   w w  w. j  a v a 2 s  . c om
    if (strClass.contains("my_account")) {
        initGoogleMap();

        /* supportMapFragment = supportMapFragment.newInstance();
         supportMapFragment.getMapAsync(this);
         FragmentManager fragmentManager = getSupportFragmentManager();
         FragmentTransaction FT = fragmentManager.beginTransaction();
         FT.replace(R.id.flContent, supportMapFragment).commit();
         */

        plotMarkers(mMyMarkersArray);
        initViewSetting(true);

    } else if (strClass.contains("log_in")) {

        /* supportMapFragment = supportMapFragment.newInstance();
         supportMapFragment.getMapAsync(this);
         FragmentManager fragmentManager = getSupportFragmentManager();
         FragmentTransaction FT = fragmentManager.beginTransaction();
         FT.replace(R.id.flContent, supportMapFragment).commit();*/
        initGoogleMap();
        plotMarkers(mMyMarkersArray);
        initViewSetting(true);

    } else if (strClass.contains("create_new_account")) {
        Fragment fragment = new log_in();
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction FT = fragmentManager.beginTransaction();
        FT.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right);
        FT.replace(R.id.flContent, fragment).commit();
    } else if (strClass.contains("help_dialog")) {
        // pw.dismiss();
        /*supportMapFragment = supportMapFragment.newInstance();
        supportMapFragment.getMapAsync(this);
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction FT = fragmentManager.beginTransaction();
        FT.replace(R.id.flContent, supportMapFragment).commit();
                
                
        plotMarkers(mMyMarkersArray);
                
                
        initViewSetting(true);*/
    }
}

From source file:com.example.mego.adas.main.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override/* w  w w  .  j a  va 2  s .  c  o m*/
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    switch (id) {
    case R.id.nav_videos:
        backgroundImageView.setVisibility(View.INVISIBLE);
        //setup the videos fragment
        VideosFragments videosFragments = new VideosFragments();
        fragmentTransaction.replace(R.id.fragment_container, videosFragments);
        fragmentTransaction.commit();
        break;

    case R.id.nav_settings:
        backgroundImageView.setVisibility(View.INVISIBLE);
        //setup the setting fragment
        SettingsFragment settingsFragment = new SettingsFragment();
        fragmentTransaction.replace(R.id.fragment_container, settingsFragment);
        fragmentTransaction.commit();
        break;
    case R.id.nav_directions:
        backgroundImageView.setVisibility(View.INVISIBLE);
        //setup the directions Fragment
        MapFragment mapFragment = (MapFragment) this.getFragmentManager()
                .findFragmentById(R.id.google_map_location);
        if (mapFragment != null) {
            this.getFragmentManager().beginTransaction().remove(mapFragment).commit();
        }
        DirectionsFragment directionsFragment = new DirectionsFragment();
        fragmentTransaction.replace(R.id.fragment_container, directionsFragment);
        fragmentTransaction.commit();
        break;
    case R.id.nav_live_streaming:
        backgroundImageView.setVisibility(View.INVISIBLE);
        //setup the live streaming fragment
        LiveStreamingFragment liveStreamingFragment = new LiveStreamingFragment();
        fragmentTransaction.replace(R.id.fragment_container, liveStreamingFragment);
        fragmentTransaction.commit();
        break;
    case R.id.nav_connect:
        backgroundImageView.setVisibility(View.INVISIBLE);
        //setup the connect fragment
        ConnectFragment connectFragment = new ConnectFragment();
        fragmentTransaction.replace(R.id.fragment_container, connectFragment);
        fragmentTransaction.commit();
        break;
    case R.id.nav_car:
        backgroundImageView.setVisibility(View.INVISIBLE);
        //setup the car fragment
        MapFragment mapFragmentUser = (MapFragment) this.getFragmentManager()
                .findFragmentById(R.id.my_location_fragment_car);
        if (mapFragmentUser != null) {
            this.getFragmentManager().beginTransaction().remove(mapFragmentUser).commit();
        }
        carFragment = new CarFragment();
        fragmentTransaction.replace(R.id.fragment_container, carFragment);
        fragmentTransaction.commit();
        break;
    case R.id.nav_about:
        backgroundImageView.setVisibility(View.INVISIBLE);
        //setup the about fragment
        AboutFragment aboutFragment = new AboutFragment();
        fragmentTransaction.replace(R.id.fragment_container, aboutFragment);
        fragmentTransaction.commit();
        break;
    case R.id.nav_user:
        MapFragment mapFragmentCar = (MapFragment) this.getFragmentManager()
                .findFragmentById(R.id.my_location_fragment_user);
        if (mapFragmentCar != null) {
            this.getFragmentManager().beginTransaction().remove(mapFragmentCar).commit();
        }
        backgroundImageView.setVisibility(View.INVISIBLE);
        //setup the user fragment
        UserFragment userFragment = new UserFragment();
        fragmentTransaction.replace(R.id.fragment_container, userFragment);
        fragmentTransaction.commit();
        break;
    case R.id.nav_help:
        backgroundImageView.setVisibility(View.INVISIBLE);
        //setup the help fragment
        HelpFragment helpFragment = new HelpFragment();
        fragmentTransaction.replace(R.id.fragment_container, helpFragment);
        fragmentTransaction.commit();
        break;
    case R.id.nav_accidents:
        backgroundImageView.setVisibility(View.INVISIBLE);
        //setup the accident fragment
        AccidentFragment accidentFragment = new AccidentFragment();
        fragmentTransaction.replace(R.id.fragment_container, accidentFragment);
        fragmentTransaction.commit();
        break;
    }

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.example.angel.parkpanda.MainActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    int id = item.getItemId();
    showhideFootWindow(0);/*w ww . jav a2  s  .com*/
    if (id == R.id.nav_menu_findparking) {
        Intent intent = new Intent(getApplicationContext(), Find_Park.class);
        startActivityForResult(intent, 2);// Activity is started with requestCode 2
        // finish();
    }
    if (id == R.id.nav_menu_account) {
        initViewSetting(false);
        if (LOGININFO.flag == 10) {
            Fragment fragment = new my_account();
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction FT = fragmentManager.beginTransaction();
            FT.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
            FT.replace(R.id.flContent, fragment).commit();
        } else {
            Fragment fragment = new log_in();
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction FT = fragmentManager.beginTransaction();
            FT.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
            FT.replace(R.id.flContent, fragment).commit();
        }

    }
    if (id == R.id.nav_menu_help) {
        int currentapiVersion = android.os.Build.VERSION.SDK_INT;

        if (currentapiVersion > 21) {
            showhideFootWindow(0);
            initViewSetting(true);

            LayoutInflater inflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.ly_my_help, null);
            layout.setAnimation(AnimationUtils.loadAnimation(this, R.anim.popupanim));
            PopupWindow optionspu = new PopupWindow(layout, DrawerLayout.LayoutParams.WRAP_CONTENT,
                    DrawerLayout.LayoutParams.WRAP_CONTENT);

            optionspu.setFocusable(true);
            optionspu.showAtLocation(layout, Gravity.CENTER, 0, 0);
            optionspu.update(0, 0, DrawerLayout.LayoutParams.WRAP_CONTENT,
                    DrawerLayout.LayoutParams.WRAP_CONTENT);
            optionspu.setAnimationStyle(R.anim.popupanim);
        } else {

            // initViewSetting(false);

            /*                Fragment fragment = new help_dialog();
                            FragmentManager fragmentManager = getSupportFragmentManager();
                            FragmentTransaction FT = fragmentManager.beginTransaction();
                            FT.setCustomAnimations(R.anim.enter_from_right,
                R.anim.exit_to_left);
                            FT.replace(R.id.flContent, fragment).commit();*/

            LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            View popupView = layoutInflater.inflate(R.layout.fragment_help_dialog, null);
            final PopupWindow optionspu = new PopupWindow(popupView, DrawerLayout.LayoutParams.WRAP_CONTENT,
                    DrawerLayout.LayoutParams.WRAP_CONTENT);

            optionspu.setFocusable(true);
            optionspu.showAtLocation(popupView, Gravity.CENTER, 0, 0);
            Button btnDismiss = (Button) popupView.findViewById(R.id.btn_help_close);

            btnDismiss.setOnClickListener(new Button.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // Toast.makeText(getApplicationContext(), "dsdsa", Toast.LENGTH_SHORT).show();
                    optionspu.dismiss();
                    plotMarkers(mMyMarkersArray);
                    initViewSetting(true);
                }

            });
        }

    }
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java

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

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String data = prefs.getString("AFilmModel", null);
    Gson gson = new Gson();

    AFilmModel aFilm = gson.fromJson(data, AFilmModel.class);
    String link = "http://nhatphim.com/index/api-detail?id=" + aFilm.getId();
    getListVideo(link);//from   w  w  w  .  j  a va 2  s.  c o m
    //  contentUri = Uri.parse("http://www.phim3s.net/phim-bo/thien-kim-tro-ve_8328/xem-phim/221808/video.mp4");
    /*   contentUri = Uri.parse("http://www.phim3s.net/phim-bo/thien-kim-tro-ve_8328/xem-phim/221808/video.mp4");*/
    contentType = 2;
    contentId = "dizzy";

    setContentView(R.layout.player_activity);
    root = findViewById(R.id.root);
    root.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                toggleControlsVisibility();
            } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                view.performClick();
            }
            return true;
        }
    });

    shutterView = findViewById(R.id.shutter);
    debugRootView = findViewById(R.id.controls_root);

    surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);
    debugTextView = (TextView) findViewById(R.id.debug_text_view);

    playerStateTextView = (TextView) findViewById(R.id.player_state_view);
    subtitleView = (SubtitleView) findViewById(R.id.subtitles);

    mediaController = new VideoControllerView(this);
    mediaController.setAnchorView((FrameLayout) root);
    mediaController.setPrevNextListeners(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //next button clicked
            Toast t = Toast.makeText(PlayerActivity.this, "click", Toast.LENGTH_SHORT);
            t.show();
        }
    }, new OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast t = Toast.makeText(PlayerActivity.this, "pt bt", Toast.LENGTH_SHORT);
            t.show();
        }
    });
    retryButton = (Button) findViewById(R.id.retry_button);
    retryButton.setOnClickListener(this);
    videoButton = (Button) findViewById(R.id.video_controls);
    audioButton = (Button) findViewById(R.id.audio_controls);
    textButton = (Button) findViewById(R.id.text_controls);

    DemoUtil.setDefaultCookieManager();
    configureSubtitleView();
    delegate = new Listener() {
        @Override
        public void GetFinish() {
            //  adapter = new NavDrawerListAdapter(PlayerActivity.this,Film.getServer());
            //  lv.setAdapter(adapter);
            contentUri = Uri.parse(Film.getServer().get(0).getLink());
            if (player == null && contentUri != null) {

                preparePlayer();
                ProgressBar progressBar = (ProgressBar) root.findViewById(R.id.progressBar);
                progressBar.setVisibility(View.GONE);
                /////////////////////////////////////////////
                FragmentManager fragmentManager;
                FragmentTransaction fragmentTransaction;
                fragmentManager = getSupportFragmentManager();
                fragmentTransaction = fragmentManager.beginTransaction();
                VerticalGridFragment verticalFragment = new VerticalGridFragment(PlayerActivity.this,
                        Film.getServer());
                fragmentTransaction.replace(R.id.view_fm, verticalFragment);
                fragmentTransaction.commit();

            }
        }
    };
    recyclerViewDesign();

}

From source file:com.example.android.aerotoolbox.MainActivity.java

public void onArticleSelected(int position) {
    // The user selected the headline of an article from the HeadlinesFragment
    EXPANSION_POSITION = 0;//  w w  w.  j  av a  2  s  .c  om
    OBLIQUE_POSITION = 0;
    // Capture the article fragment from the activity layout
    com.example.android.aerotoolbox.ContentFragment articleFrag = (com.example.android.aerotoolbox.ContentFragment) getSupportFragmentManager()
            .findFragmentById(R.id.article_fragment);

    if (articleFrag != null) {
        // If article frag is available, we're in two-pane layout...

        // Call a method in the ArticleFragment to update its content
        articleFrag.updateArticleView(position);

    } else {
        // If the frag is not available, we're in the one-pane layout and must swap frags...

        // Create fragment and give it an argument for the selected article
        com.example.android.aerotoolbox.ContentFragment newFragment = new com.example.android.aerotoolbox.ContentFragment();
        Bundle args = new Bundle();
        args.putInt(com.example.android.aerotoolbox.ContentFragment.ARG_POSITION, position);
        newFragment.setArguments(args);
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack so the user can navigate back
        transaction.replace(R.id.fragment_container, newFragment);
        transaction.addToBackStack(null);

        // Commit the transaction
        transaction.commit();
    }
}

From source file:com.andreadec.musicplayer.MainActivity.java

private void openPage(int page) {
    MusicPlayerFragment fragment;//from  w  w w.  ja v  a2s  .com
    switch (page) {
    case PAGE_BROWSER:
        fragment = new BrowserFragment();
        break;
    case PAGE_PLAYLISTS:
        fragment = new PlaylistFragment();
        break;
    case PAGE_RADIOS:
        fragment = new RadioFragment();
        break;
    case PAGE_PODCASTS:
        fragment = new PodcastsFragment();
        break;
    default:
        return;
    }
    currentPage = page;
    currentFragment = fragment;
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.remove(currentFragment);
    transaction.replace(R.id.page, fragment);
    transaction.addToBackStack(null);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    transaction.commit();
    fragmentManager.executePendingTransactions();
    drawerList.setItemChecked(currentPage, true);
    setTitle(pages[currentPage]);
}

From source file:com.asy.animations.ui.fragment.HeroesMainActivity.java

public void goToHeroeDetail(Heroe heroe, HeroesAdapter.Holder holder) {

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    heroeDetailFragment = HeroeDetailFragment.newInstance(heroe);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

        // Inflate transitions to apply
        Transition changeTransform = TransitionInflater.from(this)
                .inflateTransition(R.transition.change_image_transform);

        Transition explodeTransform = TransitionInflater.from(this)
                .inflateTransition(android.R.transition.explode);

        //            // Setup exit transition on first fragment
        heroesListFragment.setSharedElementReturnTransition(changeTransform);
        heroesListFragment.setExitTransition(explodeTransform);

        // Setup enter transition on second fragment
        heroeDetailFragment.setSharedElementEnterTransition(changeTransform);
        heroeDetailFragment.setEnterTransition(explodeTransform);

        transaction.addSharedElement(holder.getIvAvatar(), getString(R.string.transition_avatar));

    }/*  w w  w. ja v  a  2s  .  c om*/

    transaction.addToBackStack(null);

    transaction.replace(R.id.main_container, heroeDetailFragment);

    transaction.commit();
}

From source file:com.cnm.cnmrc.fragment.vodtvch.VodTvch.java

/**
 * ? ? ?  fragment VodTvch ?? loadingDataForSidrebar()? no addToBackStack ??.
 * ? MainActivity onBackPressed()? back key ?.
 * ? VodTvch fragment addToBackStack ?? ?,  ?? Base back key . 
 * back key?   ??... Base? destoryView()?  ? ?.
 * no addToBackStack(null)//from  w  w w  .  ja v  a  2s  . c  om
 * ft.replace(R.id.loading_data_panel, base)
 */
private void loadingDataForSidrebar() {
    FragmentManager fm = getActivity().getSupportFragmentManager();
    Log.i("hwang", "before vodTvch fragment count (no add to stack) --> "
            + Integer.toString(fm.getBackStackEntryCount()));

    FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
    Class<?> classObject;
    try {
        String packageName = this.getClass().getPackage().getName() + ".";
        classObject = Class.forName(packageName + mClassTypeArray[selectedCategory]); // CommonList, VodSemiDetail, VodDetail, TvchSemiDetail, TvchDetail
        Object obj = classObject.newInstance();

        Base base = ((Base) obj).newInstance(mCategoryArray[selectedCategory], true); // true : 1 depth (vod:VodSemiDetail, VodSemiDetail, VodSemiDetail, VodList)
        // true : 1 depth (tvch: TvchSemiDetail, TvchList, TvchSemiDetail, TvchSemiDetail)

        //ft.addToBackStack(null);   // addTBackStack  onBackPressed() ? ?... remove fragment onDestroyView() ?.
        ft.replace(R.id.loading_data_panel, base);
        ft.commit();
        //fm.executePendingTransactions();   // fragment? ? pending recursive error,  ?? pending .
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (java.lang.InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    Log.i("hwang", "after vodTvch fragment count (no add to stack) --> "
            + Integer.toString(fm.getBackStackEntryCount()));

    // ------------------------------------
    // ? bottom menu? depth level 
    // ------------------------------------
    Fragment f = getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_rc_bottom_menu);
    if (f != null)
        ((RcBottomMenu) f).setDepthLevelClear(); // set 1 depth
}

From source file:com.example.android.networkconnect.MainActivity.java

private void showFragment(final Fragment newfragment) {
    if (newfragment == null)
        return;//from w w w . ja  v  a 2  s . co  m

    View currentView = getCurrentFocus();

    //currentView.destroyDrawingCache();
    //currentView.clearFocus();
    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction ft = fm.beginTransaction();
    // We can also animate the changing of fragment
    //Fragment currentfragment=fm.findFragmentById(R.id.intro_fragment);
    //currentfragment.setUserVisibleHint(false);

    ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
    //ft.hide(fragment);
    // ft.remove(fragment);
    //ft.add(msimpleTextFragment,null);

    ft.replace(R.id.intro_fragment, newfragment);
    //this.mbureauFragment;
    ft.addToBackStack(null);
    //ft.detach(fragment);
    //Toast.makeText(getBaseContext(), "Changement de fragment commit: ", Toast.LENGTH_SHORT).show();
    //ft.remove(fragment);
    ft.commit();

}