Example usage for android.app FragmentTransaction commit

List of usage examples for android.app FragmentTransaction commit

Introduction

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

Prototype

public abstract int commit();

Source Link

Document

Schedules a commit of this transaction.

Usage

From source file:it.angrydroids.epub3reader.MainActivity.java

public void addPanel(SplitPanel p) {
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.add(R.id.MainLayout, p, p.getTag());
    fragmentTransaction.commit();

    panelCount++;//from  www .ja v a2s  .c  om
}

From source file:org.eyeseetea.malariacare.DashboardActivity.java

/**
 * Init the fragments//from  w ww  . j  a v  a  2 s.co m
 */
private void setFragmentTransaction(int layout, ListFragment fragment) {
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.add(layout, fragment);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ft.commit();
}

From source file:com.evandroid.musica.MainLyricActivity.java

public void updateLyricsFragment(int outAnim, String... params) { // Should only be called from SearchFragment or IdDecoder
    String artist = params[0];/*from   w  w w  . ja va2 s.c o  m*/
    String song = params[1];
    String url = null;
    if (params.length > 2)
        url = params[2];
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) getFragmentManager()
            .findFragmentByTag(LYRICS_FRAGMENT_TAG);
    if (lyricsViewFragment != null)
        lyricsViewFragment.fetchLyrics(artist, song, url);
    else {
        Lyrics lyrics = new Lyrics(Lyrics.SEARCH_ITEM);
        lyrics.setArtist(artist);
        lyrics.setTitle(song);
        lyrics.setURL(url);
        Bundle lyricsBundle = new Bundle();
        try {
            if (artist != null && song != null)
                lyricsBundle.putByteArray("lyrics", lyrics.toBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
        lyricsViewFragment = new LyricsViewFragment();
        lyricsViewFragment.setArguments(lyricsBundle);

        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        Fragment activeFragment = getDisplayedFragment(getActiveFragments());
        if (activeFragment != null) {
            prepareAnimations(activeFragment);
            fragmentTransaction.hide(activeFragment);
        }
        fragmentTransaction.add(R.id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
        lyricsViewFragment.isActiveFragment = true;
        fragmentTransaction.commit();
    }
}

From source file:com.example.pyrkesa.shwc.MainActivity.java

/**
 * Diplaying fragment view for selected nav drawer list item
 * *///from w ww  .  j  a  va 2 s.c om
private void displayView(int position) {

    Fragment fragment = null;

    switch (position) {
    case 0:
        fragment = new HomeFragment();
        mTitle = "SHWC";
        break;
    case 1:
        fragment = new ScenarioFragment();
        mTitle = "Dfinir scnarios";
        break;
    case 2:
        fragment = new RoomSettingFragment();
        mTitle = "Rglage salle";
        break;
    case 3:
        fragment = new User_Fragment();
        mTitle = "Gestion des utilisateurs";
        break;
    default:
        break;
    }

    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.test, fragment, "");
        transaction.commit();
        model.current_page = position;

        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        //getActionBar().setTitle(mNavigationDrawerItemTitles[position]);
        // getActionBar().setTitle(position);
        mDrawerLayout.closeDrawer(mDrawerList);

    } else {
        Log.e("MainActivity", "Error in creating fragment");
    }
}

From source file:de.sourcestream.movieDB.controller.TVList.java

/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 *
 * @param parent   The AdapterView where the click happened.
 * @param view     The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position The position of the view in the adapter.
 * @param id       The row id of the item that was clicked.
 *///from   w w w . j  av a 2s.c om
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    activity.resetMovieDetailsBundle();
    activity.setRestoreMovieDetailsAdapterState(true);
    activity.setRestoreMovieDetailsState(false);
    activity.setOrientationChanged(false);
    activity.resetCastDetailsBundle();
    activity.resetTvDetailsBundle();
    if (tvDetails != null && lastVisitedTV == tvList.get(position).getId() && tvDetails.getTimeOut() == 0) {
        // Old movie details retrieve info and re-init component else crash
        tvDetails.onSaveInstanceState(new Bundle());
        Bundle bundle = new Bundle();
        bundle.putInt("id", tvList.get(position).getId());
        Bundle save = tvDetails.getSave();
        tvDetails = new TVDetails();
        tvDetails.setTimeOut(0);
        tvDetails.setSave(save);
        tvDetails.setArguments(bundle);
    } else
        tvDetails = new TVDetails();

    lastVisitedTV = tvList.get(position).getId();
    tvDetails.setTitle(tvList.get(position).getTitle());
    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    Bundle bundle = new Bundle();
    bundle.putInt("id", tvList.get(position).getId());
    tvDetails.setArguments(bundle);
    transaction.replace(R.id.frame_container, tvDetails);
    // add the current transaction to the back stack:
    transaction.addToBackStack("TVList");
    transaction.commit();
    fragmentActive = true;
    activity.getTvSlideTab().showInstantToolbar();
}

From source file:org.kymjs.kjframe.KJActivity.java

/**
 * Fragment?/*from  ww w  .  ja  v  a 2s  . c  o m*/
 *
 * @param resView        ??
 * @param targetFragment ??Fragment
 * @param isBack  ??true
 */
public void changeFragment(int resView, SupportFragment targetFragment, boolean isBack) {
    if (targetFragment.equals(currentSupportFragment)) {
        return;
    }
    android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    if (!targetFragment.isAdded()) {
        transaction.add(resView, targetFragment, targetFragment.getClass().getName());
    }
    if (targetFragment.isHidden()) {
        transaction.show(targetFragment);
        targetFragment.onChange();
    }
    if (currentSupportFragment != null && currentSupportFragment.isVisible()) {
        transaction.hide(currentSupportFragment);
    }
    if (isBack) {
        transaction.addToBackStack(null);
    }
    currentSupportFragment = targetFragment;
    transaction.commit();
}

From source file:com.mastercard.masterpasswallet.fragments.MainCardFragment.java

private void setupViewpagerIndicator(int currentItem) {
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();

    Bundle data = new Bundle();
    data.putInt(ViewpagerIndicatorFragment.EXTRA_COUNT, mCards.size());
    data.putInt(ViewpagerIndicatorFragment.EXTRA_CURRENT_ITEM, currentItem);

    mViewpagerIndicator = new ViewpagerIndicatorFragment();
    mViewpagerIndicator.setArguments(data);

    ft.replace(R.id.lay_indicator_container, mViewpagerIndicator);
    ft.commit();
}

From source file:at.flack.MainActivity.java

public void redrawMailFragment() {
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.detach(MailMainActivity.getInstance());
    ft.commit();
}

From source file:at.flack.MainActivity.java

public void redrawFbFragment() {
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.detach(FacebookMainActivity.getInstance());
    ft.commit();
}

From source file:com.ht.app.RestaurantsActivity.java

@Override
protected void setupView() {

    mDrawerMenuTitles = new String[] { "Restaurants", "Masjid and Prayer Rooms", "Contact Us" };
    mDrawerMenuOnItemClickListener = new AdapterView.OnItemClickListener() {
        @Override//from  w  ww.ja  va2  s  .  c  o  m
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            if (position == 1) {
                Intent msjidIntent = new Intent(RestaurantsActivity.this, MasjidActivity.class);
                startActivity(msjidIntent);
                finish();
            } else if (position == 2) {
                Utils.showComposeEmailUI(RestaurantsActivity.this);

            }
        }
    };

    super.setupView(); // Setup left slide menu

    Utils.setStatusBarColor(this, getResources().getColor(R.color.app_red_color_dark));

    mListView = (ListView) findViewById(R.id.list);
    mListView.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
    mLoadingListAdapter = new LoadingListAdapter(this);
    mNoGPSAdapter = new NoGpsAdapter(this);
    mNoInterentConnectionAdapter = new NoInternetAdapter(this);

    mSlidingUpPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.slidingLayout);
    mSlidingUpPanelLayout.setEnableDragViewTouchEvents(true);

    int mapHeight = getResources().getDimensionPixelSize(R.dimen.map_height);
    mSlidingUpPanelLayout.setPanelHeight(mapHeight); // you can use different height here
    mSlidingUpPanelLayout.setScrollableView(mListView, mapHeight);

    mSlidingUpPanelLayout.setPanelSlideListener(this);

    // transparent view at the top of ListView
    mTransparentView = findViewById(R.id.transparentView);

    // init header view for ListView
    mTransparentHeaderView = LayoutInflater.from(this).inflate(R.layout.transparent_header_view, null, false);
    mWhiteFooterView = LayoutInflater.from(this).inflate(R.layout.white_footer_view, null, false);
    mSpaceView = mTransparentHeaderView.findViewById(R.id.space);
    mListView.addHeaderView(mTransparentHeaderView);
    mListView.addFooterView(mWhiteFooterView);

    mListView.setAdapter(mLoadingListAdapter);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            mSlidingUpPanelLayout.collapsePane();
            Restaurant selectedRestaurant = (Restaurant) mListView.getItemAtPosition(position);
            showRestaurantDetailsActivity(selectedRestaurant);

        }
    });

    mMapFragment = MapFragment.newInstance();
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.add(R.id.mapContainer, mMapFragment, "map");
    fragmentTransaction.commit();

    // Create a GoogleApiClient instance
    mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API)
            .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
    setUpMapIfNeeded();

}