List of usage examples for android.app FragmentManager beginTransaction
public abstract FragmentTransaction beginTransaction();
From source file:air.com.snagfilms.utils.ImageCache.java
/** * Locate an existing instance of this Fragment or if not found, create and * add it using FragmentManager.//www . jav a 2 s . com * * @param fm * The FragmentManager manager to use. * @return The existing instance of the Fragment or the new instance if just * created. */ private static RetainFragment findOrCreateRetainFragment(FragmentManager fm) { // Check to see if we have retained the worker fragment. RetainFragment mRetainFragment = (RetainFragment) fm.findFragmentByTag(TAG); // If not retained (or first time running), we need to create and add // it. if (mRetainFragment == null) { mRetainFragment = new RetainFragment(); fm.beginTransaction().add(mRetainFragment, TAG).commitAllowingStateLoss(); } return mRetainFragment; }
From source file:com.google.cloud.genomics.android.MainActivity.java
@Override public void onNavigationDrawerItemSelected(int position) { if (!credentialAvailable) { return;/*from w ww.j a v a2 s .com*/ } Fragment fragment = position == 0 ? new DatasetListFragment() : new JobListFragment(); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.container, fragment).commit(); }
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);// ww w . j a v a 2s .com transaction.commit(); }
From source file:com.cloudbees.gasp.activity.TwitterStreamActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getActionBar().setDisplayHomeAsUpEnabled(true); // Use simple FrameLayout for ListFragment setContentView(R.layout.gasp_frame_layout); FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ListFragment list = new ListFragment(); ft.add(R.id.fragment_content, list); // Use a simple TextView layout for ArrayAdapter constructor mAdapter = new ArrayAdapter<String>(this, R.layout.gasp_generic_textview); // Map ArrayAdapter to ListFragment list.setListAdapter(mAdapter);// w w w. ja v a2 s .c o m // RESTResponderFragments call setRetainedInstance(true) in onCreate() TwitterResponderFragment responder = (TwitterResponderFragment) fm .findFragmentByTag(getString(R.string.twitter_responder)); if (responder == null) { responder = new TwitterResponderFragment(); ft.add(responder, getString(R.string.twitter_responder)); } ft.commit(); }
From source file:cb.app.fyp.MainActivity.java
private void selectItem(int position) { Fragment fragment = new NullFragment(); switch (position) { case 0://from w ww . j a v a 2s .co m fragment = new HomeFragment(); break; case 1: fragment = new MyAppsFragment(); break; case 2: //Placeholder fragment = new SettingsFragment(); break; case 3: fragment = new AboutFragment(); } // update the main content by replacing fragments if (fragment != null) { FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer drawerListView.setItemChecked(position, true); setTitle(drawerItemTitles[position]); drawerLayout.closeDrawer(drawerListView); } else { // error in creating fragment Log.e(TAG, "Error in creating fragment"); } }
From source file:com.emotion.emotioncontrol.MainActivity.java
@Override public void onNavigationDrawerItemSelected(int position) { // update the main content by replacing fragments FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.container, getFragmentToAttach(position)).commit(); }
From source file:com.manuelpeinado.fadingactionbar.demo.NavigationDrawerActivity.java
private void selectItem(int position) { // update the main content by replacing fragments Fragment fragment = new SampleFragment(); Bundle args = new Bundle(); args.putInt(SampleFragment.ARG_IMAGE_RES, mCityImages[position]); args.putInt(SampleFragment.ARG_ACTION_BG_RES, R.drawable.ab_background); fragment.setArguments(args);/* w w w .j a v a 2 s.c o m*/ FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mCityNames[position]); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.akvelon.nutrientsguru.activity.MainActivity.java
private void selectItem(int position) { // update the main content by replacing fragments Fragment fragment = new ProductListFragment(); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.krotos139.room_z1.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.z1room = new BoardZ1Room(getApplicationContext()); server = new WebServer(getApplicationContext(), this.z1room); try {/*w ww . j av a 2 s . c o m*/ server.start(); } catch (IOException ioe) { Log.w("Httpd", "The server could not start."); } Log.w("Httpd", "Web server initialized."); this.TCPModbusThread = new Thread(new TCPModbusSlave(getApplicationContext(), this.z1room)); this.TCPModbusThread.start(); this.RTUModbus = new RTUModbusMaster(getApplicationContext(), this.z1room); mTitle = getTitle(); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.container, PlaceholderFragment.newInstance(1)).commit(); }
From source file:org.omni.roadrunner.MainActivity.java
@Override public void onNavigationDrawerItemSelected(int position) { switch (position) { case 0:// ww w . j a v a 2 s . c om mBodyFragment = StatisticsFragment.newInstance(null, null); break; case 1: mBodyFragment = PowerProfileFragment.newInstance(); break; case 2: mBodyFragment = WakelocksFragment.newInstance(); break; case 3: mBodyFragment = AlarmsFragment.newInstance(); break; default: throw new RuntimeException("Unknown sidebar element!"); } // update the main content by replacing fragments FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.container, mBodyFragment).commit(); // update title if (mSections != null) { mTitle = mSections[position]; } }