List of usage examples for android.app FragmentManager beginTransaction
public abstract FragmentTransaction beginTransaction();
From source file:com.dono.psakkos.dono.MainActivity.java
private void removeAllFragments() { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); LonelyFragment lonelyFragment = new LonelyFragment(); fragmentTransaction.remove(lonelyFragment); LabelsFragment labelsFragment = new LabelsFragment(); fragmentTransaction.remove(labelsFragment); AddLabelFragment addlabelFragment = new AddLabelFragment(); fragmentTransaction.remove(addlabelFragment); KeyFragment keyFragment = new KeyFragment(); fragmentTransaction.remove(keyFragment); fragmentTransaction.commit();/*w ww.ja v a2 s.co m*/ }
From source file:com.zachrohde.gpsautodash.MainActivity.java
@Override public void onNavigationDrawerItemSelected(int position) { FragmentManager fragmentManager = getFragmentManager(); switch (position) { case 0:/*from w ww. j a va2 s .c o m*/ // Update the main content by setting the Dashboard fragment. fragmentManager.beginTransaction().replace(R.id.container, DashboardFragment.newInstance(position + 1)) .commit(); break; case 1: // Update the main content by setting the Prefs fragment. fragmentManager.beginTransaction().replace(R.id.container, SettingsFragment.newInstance(position + 1)) .commit(); break; } }
From source file:quarkstar.android.javainterviewquestions.MainActivity.java
private void selectItem(int position) { Fragment fragment = new CardListFragment(this, position); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); mDrawerList.setItemChecked(position, true); setTitle(mPlanetTitles[position]);/*w w w . ja v a 2 s . co m*/ mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.quaninventory.scanner.activities.DrawerActivity.java
private void selectItem(int position) { FragmentManager fragmentManager = getFragmentManager(); switch (position) { case 0://from w w w . j av a2s . c o m fragmentManager.beginTransaction().replace(R.id.content_frame, new InventoryList(), "IL").commit(); break; case 1: exitApp(); break; default: break; } // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.veggies.android.todoList.MainActivity.java
private void selectItem(int position) { String[] drawer_array = getResources().getStringArray(R.array.drawer_array); if (position == mDrawerItems.get(this.getResources().getString(R.string.drawer_item_list))) { listFragmentFlag = true;/* www . j a va2 s .com*/ setActionMenu(); Bundle data = new Bundle(); data.putInt(TYPE, 5); //selected To-do list // update the main content by replacing fragments Fragment fragment = new ListViewFragment(); fragment.setArguments(data); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment, TODOFRAG).commit(); } else if (position == mDrawerItems.get(this.getResources().getString(R.string.drawer_item_setting))) { listFragmentFlag = false; hideActionMenu(); //selected setting // update the main content by replacing fragments Fragment fragment = new SettingFragment(); 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(drawer_array[position]); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.rastating.droidbeard.fragments.ComingEpisodesFragment.java
@Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { UpcomingEpisode episode = mEpisodes[position]; TVShowSummary show = new TVShowSummary(episode.getShowName()); show.setTvDbId(episode.getTVDBID()); FragmentManager manager = this.getFragmentManager(); ShowFragment fragment = new ShowFragment(); fragment.setShouldReturnToUpcomingEpisodes(true); fragment.setTvShowSummary(show);// w w w. j a v a2 s . c o m manager.beginTransaction().replace(R.id.container, fragment).commit(); }
From source file:com.rastating.droidbeard.MainActivity.java
public void displayAndRefreshShowsFragment() { Bundle bundle = new Bundle(); bundle.putBoolean("resetAdapter", true); mShowsFragment = new ShowsFragment(); mShowsFragment.setArguments(bundle); FragmentManager manager = this.getFragmentManager(); manager.beginTransaction().replace(R.id.container, mShowsFragment).commit(); setCurrentFragment(mShowsFragment);/*from www . j ava 2s.co m*/ }
From source file:org.kosmakoff.pocketreckoner.ui.MainActivity.java
private void selectMenuItem(int position) { DrawerMenuItem selectedItem = (DrawerMenuItem) mDrawerList.getAdapter().getItem(position); setTitle(selectedItem.getTitle());/*from w w w . j a va 2 s . c o m*/ mDrawerList.setItemChecked(position, true); Fragment fragmentToShow; currentMenu = selectedItem.getMenuItemType(); switch (currentMenu) { case PEOPLE: fragmentToShow = new PeopleFragment(); Log.d(LOG_TAG, "Showing people fragment"); break; case CHECKS: fragmentToShow = new ChecksFragment(); Log.d(LOG_TAG, "Showing checks fragment"); break; default: throw new IllegalArgumentException( "Unsupported menu item type: " + String.valueOf(selectedItem.getMenuItemType())); } FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragmentToShow).commit(); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.example.atsuto5.yahoo_rss_reader.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mMainTopicsFragment = new MainTopicsFragment(); android.app.FragmentManager fragmentManager = getFragmentManager(); android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(R.id.fragment_container, mMainTopicsFragment); fragmentTransaction.commit();/*from w ww.j a va 2s. c o m*/ mToolbar = (Toolbar) findViewById(R.id.mainToolbar); mToolbar.setTitle(""); mToolbar.setTitleMargin(140, 0, 0, 0); setSupportActionBar(mToolbar); final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); SharedPreferences data = getSharedPreferences("DataSave", Context.MODE_PRIVATE); String username = data.getString("USERNAME", "User Name"); if (drawerFlag) { mUserNameTextView = (TextView) drawerView.findViewById(R.id.userName); mUserNameTextView.setText(username); drawerFlag = false; } } }; drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); }
From source file:com.commonsware.android.pagercolumns.MainActivity.java
private void populateColumn(FragmentManager fm, FragmentTransaction ft, SamplePagerAdapter adapter, int position, int slot) { EditorFragment f = adapter.getExistingFragment(position); if (f == null) { f = adapter.createFragment(buildTitle(position)); } else {/*from w w w. ja v a 2 s.c om*/ fm.beginTransaction().remove(f).commit(); fm.executePendingTransactions(); } ft.add(slot, f, buildTag(position)); }