List of usage examples for android.app FragmentTransaction replace
public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment);
From source file:edu.jcu.cs470.togenda.MainActivity.java
private void selectItem(int position) { //switches to the correct fragment. Fragment newFragment;/*from w w w . j av a 2 s . c o m*/ FragmentTransaction transaction = getFragmentManager().beginTransaction(); switch (position) { case 0: newFragment = new AgendaFragment(); transaction.replace(R.id.content_frame, newFragment); transaction.addToBackStack(null); transaction.commit(); gPosition = position; setTitle(pageList[position]); break; case 1: Log.d("Case1", "test"); newFragment = new ToDoFragment(); transaction.replace(R.id.content_frame, newFragment); transaction.addToBackStack(null); transaction.commit(); Log.d("Case1", "test"); gPosition = position; setTitle(pageList[position]); break; case 2: newFragment = new CalendarFragment(); transaction.replace(R.id.content_frame, newFragment); transaction.addToBackStack(null); transaction.commit(); gPosition = position; setTitle(pageList[position]); break; case 3: Intent intent = new Intent(this, SettingsActivity.class); startActivity(intent); break; } mDrawerLayout.closeDrawer(mDrawerList); }
From source file:xyz.abcapp.dotalife.ui.Activity_Main.java
@Override protected void onCreate(final Bundle b) { super.onCreate(b); startService(new Intent(this, SensorListener.class)); if (b == null) { // Create new fragment and transaction Fragment newFragment = new Fragment_Overview(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); // Replace whatever is in the fragment_container view with this // fragment, // and add the transaction to the back stack transaction.replace(android.R.id.content, newFragment); // Commit the transaction transaction.commit();//from w w w.ja va2 s . c om } GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this, this, this); builder.addApi(Games.API, Games.GamesOptions.builder().build()); builder.addScope(Games.SCOPE_GAMES); builder.addApi(Fitness.HISTORY_API); builder.addApi(Fitness.RECORDING_API); builder.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)); mGoogleApiClient = builder.build(); if (!getSharedPreferences("pedometer", Context.MODE_PRIVATE).contains("timezone")) { getSharedPreferences("pedometer", Context.MODE_PRIVATE).edit() .putString("timezone", TimeZone.getDefault().getID()).commit(); } }
From source file:com.sitewhere.android.example.MainActivity.java
/** * Adds the connectivity wizard if preferences have not been set. *///from ww w. jav a2s .c o m protected void initExampleApplication() { FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); example = new ExampleFragment(); fragmentTransaction.replace(R.id.container, example); fragmentTransaction.commit(); messageClient.setCallback(this); messageClient.connect(MqttServicePreferences.read(this)); //getActionBar().setTitle("SiteWhere Example"); }
From source file:me.isassist.isa.MainActivity.java
@SuppressWarnings("StatementWithEmptyBody") @Override//from w w w . j av a 2s . c om public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); Fragment fragment = new ListFragment(); Bundle args = new Bundle(); if (mLastLocation == null) { Toast.makeText(this, "Waiting for the location...", Toast.LENGTH_LONG).show(); return false; } switch (id) { case R.id.nav_atms: { args.putSerializable("API_TYPE", Bihapi.CASH_MACHINES); mListType = Bihapi.CASH_MACHINES; break; } case R.id.nav_bikes: { args.putSerializable("API_TYPE", Bihapi.VETURILO); mListType = Bihapi.VETURILO; break; } case R.id.nav_city_offices: { args.putSerializable("API_TYPE", Bihapi.CITY_OFFICES); mListType = Bihapi.CITY_OFFICES; break; } case R.id.nav_dormitories: { args.putSerializable("API_TYPE", Bihapi.DORMITORIES); mListType = Bihapi.DORMITORIES; break; } case R.id.nav_hotels: { args.putSerializable("API_TYPE", Bihapi.HOTELS); mListType = Bihapi.HOTELS; break; } case R.id.nav_pharmacies: { args.putSerializable("API_TYPE", Bihapi.PHARMACIES); mListType = Bihapi.PHARMACIES; break; } case R.id.nav_sport_fields: { args.putSerializable("API_TYPE", Bihapi.SPORT_FIELDS); mListType = Bihapi.SPORT_FIELDS; break; } case R.id.nav_swimming: { args.putSerializable("API_TYPE", Bihapi.SWIMMING_POOLS); mListType = Bihapi.SWIMMING_POOLS; break; } case R.id.nav_police_offices: { args.putSerializable("API_TYPE", Bihapi.POLICE_OFFICES); mListType = Bihapi.POLICE_OFFICES; break; } case R.id.nav_theaters: { args.putSerializable("API_TYPE", Bihapi.THEATRES); mListType = Bihapi.THEATRES; break; } } fragment.setArguments(args); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, fragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
From source file:it.gmariotti.cardslib.demo.MainNativeActivity.java
private void openFragment(BaseFragment baseFragment) { if (baseFragment != null) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.fragment_main, baseFragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit();/*from ww w. j a va2s. c om*/ if (baseFragment.getTitleResourceId() > 0) mCurrentTitle = baseFragment.getTitleResourceId(); } }
From source file:com.ffmpeger.card.MainNativeActivity.java
private void openFragment(BaseFragment baseFragment) { if (baseFragment != null) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(com.ffmpeger.card.R.id.fragment_main, baseFragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit();//w ww .ja v a 2 s . c om if (baseFragment.getTitleResourceId() > 0) mCurrentTitle = baseFragment.getTitleResourceId(); } }
From source file:com.mediatek.miravision.ui.MiraVisionActivity.java
private void show(FragmentManager fm, Fragment fragment, int orientation) { setRequestedOrientation(orientation); final FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.content_frame, fragment); ft.commitAllowingStateLoss();/*w ww. ja va2 s . c o m*/ }
From source file:it.gmariotti.cardslib.demo.MainActivity.java
private void openFragment(BaseFragment baseFragment) { if (baseFragment != null) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.fragment_main, baseFragment); //fragmentTransaction.addToBackStack(null); fragmentTransaction.commit();/*from w w w . j ava2s .c om*/ if (baseFragment.getTitleResourceId() > 0) mCurrentTitle = baseFragment.getTitleResourceId(); } }
From source file:de.linuxwhatelse.android.notify.activities.MainActivity.java
@Override public boolean onNavigationItemSelected(MenuItem item) { FragmentTransaction transaction; switch (item.getItemId()) { case R.id.navdrawer_apps: transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.main_container, new ApplicationsFragment()); transaction.commit();//from www. j a v a 2 s.c om break; case R.id.navdrawer_events: transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.main_container, new EventsPreferenceFragment()); transaction.commit(); break; case R.id.navdrawer_devices: transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.main_container, new ClientsFragment()); transaction.commit(); break; case R.id.navdrawer_snooze_notifications_only: case R.id.navdrawer_snooze_all_events: SnoozeDialogFragment dialog = new SnoozeDialogFragment(); if (item.getItemId() == R.id.navdrawer_snooze_notifications_only) { dialog.setTitle(getString(R.string.dialog_snooze_notifications_title)); dialog.show(getFragmentManager(), Notify.SNOOZE_NOTIFICATIONS); } else { dialog.setTitle(getString(R.string.dialog_snooze_events_title)); dialog.show(getFragmentManager(), Notify.SNOOZE_ALL); } break; case R.id.navdrawer_donate: billingProcessor = new BillingProcessor(this, Notify.GOOGLE_PLAY_LICENSE_KEY, this); break; case R.id.navdrawer_about: startActivity(new Intent(this, AboutPreferenceActivity.class)); break; case R.id.navdrawer_settings: startActivity(new Intent(this, PreferenceActivity.class)); break; } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer == null) return false; drawer.closeDrawer(GravityCompat.START); return true; }
From source file:com.sitewhere.android.example.MainActivity.java
/** * Adds the connectivity wizard if preferences have not been set. *//* ww w . j av a2 s .c om*/ protected void initConnectivityWizard() { FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); wizard = new ConnectivityWizardFragment(); wizard.setWizardListener(this); fragmentTransaction.replace(R.id.container, wizard); fragmentTransaction.commit(); //getActionBar().setTitle("SiteWhere Device Setup"); }