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.commonsware.android.arXiv.ArticleList.java

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

    FrameLayout fl = new FrameLayout(this);
    fl.setId(android.R.id.content);//w  ww .  j a  v a  2  s  .co  m
    setContentView(fl);

    Intent intent = getIntent();
    name = intent.getStringExtra("keyname");
    query = intent.getStringExtra("keyquery");
    url = intent.getStringExtra("keyurl");
    favorite = intent.getBooleanExtra("favorite", false);

    ActionBar ab = getSupportActionBar();
    ab.setTitle(name);
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setHomeButtonEnabled(true);

    FragmentManager fm = getSupportFragmentManager();
    if (savedInstanceState == null) {
        articleListFragment = new ArticleListFragment();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(android.R.id.content, articleListFragment);
        ft.commit();
    } else {
        Fragment f = fm.findFragmentById(android.R.id.content);
        if (f instanceof ArticleListFragment)
            articleListFragment = (ArticleListFragment) f;
    }
}

From source file:com.demo.maat.hello_rxjava.DebounceEditTextActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.debounce_activity_main);

    if (savedInstanceState == null) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        DebounceEditTextFragment fragment = new DebounceEditTextFragment();
        transaction.replace(R.id.sample_content_fragment, fragment);
        transaction.commit();/*from   w  ww.j  av  a2  s.c  o m*/
    }
}

From source file:com.asksven.betterbatterystats.PackageInfoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // setTheme(SampleList.THEME); //Used for theme switching in samples
    super.onCreate(savedInstanceState);

    setContentView(R.layout.package_info);

    if (savedInstanceState == null) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        PackageInfoTabsFragment fragment = new PackageInfoTabsFragment();
        transaction.replace(R.id.sample_content_fragment, fragment);
        transaction.commit();/* ww  w .  ja v a  2s. c o  m*/
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //toolbar.setLogo(R.drawable.ic_launcher);
    toolbar.setTitle(getString(R.string.label_packageinfo));
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

}

From source file:com.amazonaws.devicefarm.android.referenceapp.Activities.MainActivity.java

/**
 * Displays a specific fragment from a specific position in the drawer list
 * @param position/* www.  j  a v a2  s.com*/
 */
private void displayFragment(int position) {
    Fragment newFragment;
    //Checks if the fragment has tabs associated with it.
    if (!data.get(position).isHas_tabs()) {
        newFragment = FragmentEnum.valueOf(data.get(position).getFragment_id()).getFragment();
    } else {
        newFragment = new TabFragmentContainer();
        Bundle args = new Bundle();
        args.putParcelableArrayList(getString(R.string.tab_fragment_bundle_key),
                (ArrayList<? extends Parcelable>) data.get(position).getTabs());
        newFragment.setArguments(args);
    }

    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.container_body, newFragment);
    fragmentTransaction.commit();

    toolbarTitle.setText(data.get(position).getHeadline());
}

From source file:cn.sharesdk.analysis.example.FragmentStack.java

void addFragmentToStack() {
    mStackLevel++;//from   w  w  w. ja v a  2s.  com

    // Instantiate a new fragment.
    Fragment newFragment = CountingFragment.newInstance(mStackLevel);

    // Add the fragment to the activity, pushing this transaction
    // on to the back stack.
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.simple_fragment, newFragment);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.addToBackStack(null);
    ft.commit();
}

From source file:com.example.android.slidingtabsbasic.SlidingTabs.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_slidingtabs);

    if (savedInstanceState == null) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        SlidingTabsBasicFragment fragment = new SlidingTabsBasicFragment();
        transaction.replace(R.id.sample_content_fragment, fragment);
        transaction.commit();/*from  w ww.j  a v a 2  s  .c om*/
    }
}

From source file:com.dd.courier.activity.RegistActivity.java

/**
 * fragment?//from w  ww . j  a v  a 2  s. c o  m
 */
private void replaceFragment() {
    // TODO Auto-generated method stub
    if (second == null) {
        second = new RegistFragmentSecond();
    }
    FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
    beginTransaction.replace(R.id.regist_frame, second);
    beginTransaction.addToBackStack("second");
    beginTransaction.commit();
}

From source file:com.ae.apps.tripmeter.activities.MainActivity.java

/**
 * Update the fragment//w  ww. j av a 2 s .c  o m
 * @param itemId
 */
private void updateDisplayedFragment(int itemId) {
    Fragment fragment = null;
    switch (itemId) {
    case R.id.action_trip_calc:
        fragment = FuelCalcFragment.newInstance();
        break;
    // Both items below point to coming soon fragments
    case R.id.action_fuel_price:
        fragment = FuelPricesFragment.newInstance("", "");
        break;
    case R.id.action_trip_expenses:
        fragment = TripExpensesFragment.newInstance();
        break;
    }

    final FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.fragment_container, fragment).commit();
}

From source file:cl.ipp.katbag.fragment.Board.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    v = inflater.inflate(R.layout.fragment_board, container, false);
    mainActivity = (MainActivity) super.getActivity();

    notRegister = (TextView) v.findViewById(R.id.board_not_register);

    boardListView = (DragSortListView) v.findViewById(R.id.board_list_view);
    boardListView.setOnItemClickListener(new OnItemClickListener() {
        @Override//from   w  ww.j  a  v  a  2 s  .com
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            TextView idApp = (TextView) view.findViewById(R.id.board_row_id);
            TextView typeApp = (TextView) view.findViewById(R.id.board_row_type);
            TextView nameApp = (TextView) view.findViewById(R.id.board_row_name);

            if (typeApp.getText().toString().contentEquals(MainActivity.TYPE_APP_GAME))
                mFragment = new Player();
            else
                mFragment = new PlayerBook();

            Bundle bundle = new Bundle();
            bundle.putLong("id_app", Long.parseLong(idApp.getText().toString()));
            bundle.putString("name_app", nameApp.getText().toString());
            bundle.putString("type_app", typeApp.getText().toString());
            bundle.putBoolean("editMode", false);

            mFragment.setArguments(bundle);
            FragmentTransaction t = getActivity().getSupportFragmentManager().beginTransaction();
            t.replace(R.id.fragment_main_container, mFragment);
            t.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            t.addToBackStack(mFragment.getClass().getSimpleName());
            t.commit();
        }
    });

    return v;
}

From source file:com.android.talkbacktests.MainActivity.java

/**
 * Replaces the fragment holder with a new fragment, adds the fragment transaction to the
 * back stack./*  ww  w.ja v a  2 s .  c om*/
 *
 * @param fragment The fragment to show.
 * @param name     Name of the fragment, used to identify the fragment when popping up the back
 *                 stack.
 */
private void switchFragment(Fragment fragment, String name) {
    final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.fragment_holder, fragment);
    transaction.addToBackStack(name);
    transaction.commit();
}