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:Main.java

public static void replaceFragment(FragmentManager manager, int parent, Fragment fragment) {
    FragmentTransaction ft = manager.beginTransaction();
    ft.replace(parent, fragment);
    ft.addToBackStack(null);//from www .java2s. co  m
    ft.commit();
}

From source file:cn.edu.wyu.documentviewer.RecentsCreateFragment.java

public static void show(FragmentManager fm) {
    final RecentsCreateFragment fragment = new RecentsCreateFragment();
    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_directory, fragment);
    ft.commitAllowingStateLoss();//  w  w w. j  a v  a 2s . co m
}

From source file:net.forkk.autocron.EditComponentActivity.java

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

    Intent intent = getIntent();//from  www .  j a  v  a 2  s  .c  o m
    assert intent != null;

    ComponentPointer pointer = (ComponentPointer) intent.getSerializableExtra(EXTRA_COMPONENT_POINTER);

    // Hack to get the title to display properly.
    String componentName = "";
    if (pointer instanceof Rule.Pointer)
        componentName = getString(R.string.rule_upper);
    if (pointer instanceof Action.Pointer)
        componentName = getString(R.string.action_upper);
    if (pointer instanceof Trigger.Pointer)
        componentName = getString(R.string.trigger_upper);
    setTitle(getString(R.string.title_activity_edit_component, componentName));

    if (savedInstanceState == null) {
        Bundle fragArgs = new Bundle();
        fragArgs.putSerializable(ComponentPreferenceFragment.VALUE_COMPONENT_POINTER, pointer);

        ComponentPreferenceFragment fragment = new ComponentPreferenceFragment();
        fragment.setArguments(fragArgs);

        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.fragment_edit_component_container, fragment);
        transaction.commit();
    }
}

From source file:com.qrcodereader.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getWindowManager().getDefaultDisplay().getSize(screenParametersPoint);
    layout = (RelativeLayout) findViewById(R.id.main_layout);
    if (savedInstanceState == null) {
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.replace(layout.getId(), new FragmentDecoder());
        fragmentTransaction.commit();//from  w w  w.j a  v a 2  s.  c om
    }
}

From source file:edu.umich.titusj.tsr.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(edu.umich.titusj.tsr.R.layout.activity_main);
    getWindowManager().getDefaultDisplay().getSize(screenParametersPoint);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    layout = (FrameLayout) findViewById(edu.umich.titusj.tsr.R.id.main_layout);
    if (savedInstanceState == null) {
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.replace(layout.getId(), new Camera2Fragment());
        fragmentTransaction.commit();//  w  ww.j  a v a  2  s  .co m
    }
}

From source file:com.nostra13.universalimageloader.sample.ui.activity.activity.ProductListActivity.java

private void displayListFragment(FragmentTransaction ft) {
    if (mAdapter == null) {
        mAdapter = new ProductListFragment();
    }/*from w  w  w  .ja  va  2s . c om*/
    ft.replace(android.R.id.content, mAdapter).commit();
}

From source file:fr.qinder.layout.DrawerLayoutActivity.java

public void setContentFragment(String className, boolean withHistory) {
    DrawerLayoutFragment fragment;/*ww w.jav  a  2s  . co m*/
    try {
        fragment = (DrawerLayoutFragment) Class.forName(className).newInstance();
    } catch (InstantiationException e) {
        fragment = null;
    } catch (IllegalAccessException e) {
        fragment = null;
    } catch (ClassNotFoundException e) {
        fragment = null;
    }
    if (fragment != null) {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(mDrawerLayoutContent, fragment);
        if (withHistory) {
            ft.addToBackStack(null);
        }
        ft.commit();
        getSupportActionBar().setTitle(fragment.getTitle());
    }
}

From source file:com.example.kyle.fragmentexample.MainActivity.java

public void replaceFragment(Fragment fragment) {
    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    transaction.replace(R.id.fragment_container, fragment);
    transaction.addToBackStack(null);//  w  w  w  .jav a 2  s .c  o m
    transaction.commit();
}

From source file:org.code4hr.okcandidate.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from w w w.j av a  2  s. c o  m

    if (savedInstanceState == null) {
        FragmentTransaction tx = getFragmentManager().beginTransaction();
        tx.replace(R.id.content_frame, new NeighborhoodsFragment());
        //tx.replace(R.id.content_frame, CandidateFragment.newInstance(4055));
        tx.commit();
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}

From source file:org.code4hr.okcandidate.HomeActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override/*from   w  w w  .j a va  2  s.c  o  m*/
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    switch (id) {
    case R.id.nav_survey: {

        FragmentTransaction tx = getFragmentManager().beginTransaction();
        tx.replace(R.id.content_frame, new NeighborhoodsFragment());
        tx.addToBackStack(null);
        tx.commit();
        break;
    }
    case R.id.nav_results: {
        SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
        int survey_id = sharedPreferences.getInt("survey_response_id", 0);
        if (survey_id != 0) {
            FragmentTransaction tx = getFragmentManager().beginTransaction();
            tx.replace(R.id.content_frame, CandidateFragment.newInstance(survey_id));
            tx.addToBackStack(null);
            tx.commit();
        } else {
            Toast.makeText(this, R.string.no_survey_error, Toast.LENGTH_SHORT).show();
        }
        break;
    }
    }

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