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.awt.supark.MainActivity.java

public void openAddCarFragment(final View view) {
    Bundle args = new Bundle();
    args.putInt("editid", -1);
    fragment = new EditCar();
    fragment.setArguments(args);/*from   ww  w . ja v a 2  s  . c  om*/

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.fragment_slideup, R.anim.fragment_fadeout);
    fragmentTransaction.replace(R.id.otherContent, fragment);
    fragmentTransaction.commit();

}

From source file:com.achep.base.ui.activities.SettingsActivity.java

/**
 * Switch to a specific Fragment with taking care of validation, Title and BackStack
 *///from  ww  w.ja  v  a 2 s .  co  m
private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate, boolean addToBackStack,
        int titleResId, CharSequence title, boolean withTransition) {
    if (validate && !isValidFragment(fragmentName)) {
        String message = "Invalid fragment for this activity: " + fragmentName;
        throw new IllegalArgumentException(message);
    }

    Fragment f = Fragment.instantiate(this, fragmentName, args);
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(android.R.id.content, f);

    if (withTransition && Device.hasKitKatApi())
        TransitionManager.beginDelayedTransition(mContent);
    if (addToBackStack)
        transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
    if (titleResId > 0) {
        transaction.setBreadCrumbTitle(titleResId);
    } else if (title != null) {
        transaction.setBreadCrumbTitle(title);
    }

    transaction.commitAllowingStateLoss();
    getFragmentManager().executePendingTransactions();
    return f;
}

From source file:com.bullmobi.base.ui.activities.SettingsActivity.java

/**
 * Switch to a specific Fragment with taking care of validation, Title and BackStack
 *//* w ww  .  ja v  a2 s .  c o  m*/
private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate, boolean addToBackStack,
        int titleResId, CharSequence title, boolean withTransition) {
    if (validate && !isValidFragment(fragmentName)) {
        String message = "Invalid fragment for this activity: " + fragmentName;
        throw new IllegalArgumentException(message);
    }

    Fragment f = Fragment.instantiate(this, fragmentName, args);
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.main_content, f);

    if (withTransition && Device.hasKitKatApi())
        TransitionManager.beginDelayedTransition(mContent);
    if (addToBackStack)
        transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
    if (titleResId > 0) {
        transaction.setBreadCrumbTitle(titleResId);
    } else if (title != null) {
        transaction.setBreadCrumbTitle(title);
    }

    transaction.commitAllowingStateLoss();
    getFragmentManager().executePendingTransactions();
    return f;
}

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

@Override
public void onConnected(Bundle connectionHint) {
    // Reaching onConnected means we consider the user signed in.
    Log.i(TAG, "onConnected");

    // Update the user interface to reflect that the user is signed in.
    mSignInButton.setEnabled(false);//from w w  w.  jav a2  s. co  m

    signInUpdateLayout();
    if (!notifyServer) {
        new HttpRequestTask().execute();
        notifyServer = true;
    }
    // Retrieve some profile information to personalize our app for the user.
    currentUser = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
    gid = currentUser.getId();
    username = currentUser.getDisplayName();

    Log.d("[onConnected]", username);

    slidingTabsColorsFragment.setGid(gid);
    slidingTabsColorsFragment.setUsername(username);
    slidingTabsColorsFragment.setFriends(friendList);

    Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(this);

    // Indicate that the sign in process is complete.
    mSignInProgress = STATE_DEFAULT;

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    Bundle args = new Bundle();
    args.putString("gid", gid);
    args.putString("friends", friendList);

    transaction.replace(R.id.sample_content_fragment, slidingTabsColorsFragment);
    transaction.commit();

}

From source file:com.awt.supark.MainActivity.java

public void openCarFragment(View view, boolean animation) {
    fragment = new CarsFragment();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if (animation) {
        fragmentTransaction.setCustomAnimations(R.anim.fragment_fadein, R.anim.fragment_slidedown);
    }/*w w  w  .  j  av  a2  s.  c  om*/

    fragmentTransaction.replace(R.id.otherContent, fragment);
    fragmentTransaction.commit();
}

From source file:com.example.d062654.faciliman._2f_FacilityView.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ll = (RelativeLayout) inflater.inflate(R.layout.facilityview, container, false);

    final RecyclerView recyclerView = (RecyclerView) new RecyclerView(ll.getContext()); //ll.findViewById(R.id.incidents_recycler_view);

    recyclerView.setLayoutManager(new LinearLayoutManager(ll.getContext()));

    Call<List<IncidentRequest>> call = Connection.getApiInterface().getIncidents(username);
    call.enqueue(new Callback<List<IncidentRequest>>() {
        @Override//from  w  ww .j a  v a 2 s  .  c o  m
        public void onResponse(Call<List<IncidentRequest>> call, Response<List<IncidentRequest>> response) {
            int statusCode = response.code();
            final List<IncidentRequest> incidents = (List<IncidentRequest>) response.body();
            System.out.println(incidents.get(0));
            IncidentsAdapter adapter = new IncidentsAdapter(incidents, R.layout.list_item_incident,
                    ll.getContext());
            recyclerView.setAdapter(adapter);
            adapter.onDataChanged(incidents);
            ll.addView(recyclerView);
            recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(ll.getContext(), recyclerView,
                    new RecyclerItemClickListener.OnItemClickListener() {
                        @Override
                        public void onItemClick(View view, int position) {
                            // do whatever
                            FragmentTransaction transaction = fragact.getSupportFragmentManager()
                                    .beginTransaction();
                            _3f_FacilityDetailed newFragment = new _3f_FacilityDetailed();
                            newFragment.incident = incidents.get(position);
                            newFragment.user = username;
                            // 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();

                        }

                        @Override
                        public void onLongItemClick(View view, int position) {
                            // do whatever
                        }
                    }));
        }

        @Override
        public void onFailure(Call<List<IncidentRequest>> call, Throwable t) {
            // Log error here since request failed
            Log.e(TAG, t.toString());
        }
    });

    return ll;
}

From source file:com.example.d062654.faciliman._2_IncidentPicture.java

@Override
public void onClick(View v) {
    Toast.makeText(this.ll.getContext(), "Das ist das 4. Fragment", Toast.LENGTH_SHORT).show();

    if (v.getResources().getResourceName(v.getId()).substring(30).contentEquals("id/send_button")) {
        // creates RequestBody instance from file
        uploadPhoto();/*from ww w  .  j  a  v  a 2 s . c o  m*/

        FragmentTransaction transaction = fragact.getSupportFragmentManager().beginTransaction();
        _3_IncidentDescription newFragment = new _3_IncidentDescription();
        newFragment.user = user;
        newFragment.imageFileName = imageFileName + ".jpg";

        // 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.awt.supark.MainActivity.java

public void openCarFragment(View view, int editid) {
    Bundle args = new Bundle();
    args.putInt("editid", editid);
    fragment = new EditCar();

    if (editid == -1) {
        fragment = new CarsFragment();
    }/*from   ww w.jav a2s  . c  o m*/

    fragment.setArguments(args);
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if (editid == -1) {
        fragmentTransaction.setCustomAnimations(R.anim.fragment_fadein, R.anim.fragment_slidedown);
    } else {
        fragmentTransaction.setCustomAnimations(R.anim.fragment_slideup, R.anim.fragment_fadeout);
    }

    fragmentTransaction.replace(R.id.otherContent, fragment);
    fragmentTransaction.commit();
}

From source file:com.esri.android.ecologicalmarineunitexplorer.MainActivity.java

/**
 * Show the view with the water column profiles
 * @param point - Point representing clicked geo location
 */// www  .  j  a va 2s  .c  om
private void showWaterColumnProfile(final Point point) {
    // Remove water column, summary, text and button
    mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
    // hideMapView();

    setUpWaterProfileToolbar();

    final FrameLayout layout = (FrameLayout) findViewById(R.id.chartContainer);
    if (layout != null) {
        layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        layout.requestLayout();
    }

    final WaterProfileFragment waterProfileFragment = WaterProfileFragment.newInstance();
    new WaterProfilePresenter(point, waterProfileFragment, mDataManager);

    // Add the chart view to the column container
    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    final Fragment f = fm.findFragmentById(R.id.chartContainer);
    if (f == null) {
        transaction.addToBackStack(getString(R.string.fragment_detail_chart));
    }
    transaction.replace(R.id.chartContainer, waterProfileFragment);
    transaction.commit();

    // Hide the FAB
    mFab.setVisibility(View.INVISIBLE);

    mInMapState = false;
}

From source file:com.esri.android.ecologicalmarineunitexplorer.MainActivity.java

/**
 * Show the candlestick charts for a specific EMU layer
 * @param emuName - int representing an EMU layer name
 *//*from  w  w w .ja  va  2s .  c  om*/
private void showSummaryDetail(final int emuName) {
    // Hide the bottom sheet containing the summary view
    mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);

    // Expand the layout for the charts
    final FrameLayout layout = (FrameLayout) findViewById(R.id.chartContainer);
    if (layout != null) {
        layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        layout.requestLayout();
    }

    if (mSummaryChartFragment == null) {
        mSummaryChartFragment = SummaryChartFragment.newInstance();
        mSummaryChartPresenter = new SummaryChartPresenter(emuName, mSummaryChartFragment, mDataManager);
    } else {
        mSummaryChartPresenter.setEmuName(emuName);
    }

    // Add the chart view to the column container
    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    final Fragment f = fm.findFragmentById(R.id.chartContainer);
    if (f == null) {
        transaction.addToBackStack(getString(R.string.fragment_detail_chart));
    }
    transaction.replace(R.id.chartContainer, mSummaryChartFragment);
    transaction.commit();

    // Hide the FAB
    mFab.setVisibility(View.INVISIBLE);
    mInMapState = false;

    setUpChartSummaryToolbar(emuName);
}