List of usage examples for android.support.v4.app FragmentTransaction replace
public abstract FragmentTransaction replace(int containerViewId, Fragment fragment);
From source file:co.dilaver.quoter.activities.MainActivity.java
@Override public boolean onNavigationItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.qod: if (getSupportActionBar() != null) { getSupportActionBar().setTitle(getString(R.string.str_QOD)); }//from w ww. j a v a2s .co m qodFavorite.setVisible(true); qodShare.setVisible(true); qodCopy.setVisible(true); wyoDone.setVisible(false); wyoShare.setVisible(false); pqInfo.setVisible(false); fragment = new QODFragment(); break; case R.id.qodPopular: if (getSupportActionBar() != null) { getSupportActionBar().setTitle(getString(R.string.str_PopularQuotes)); } qodFavorite.setVisible(false); qodShare.setVisible(false); qodCopy.setVisible(false); wyoDone.setVisible(false); wyoShare.setVisible(false); pqInfo.setVisible(true); fragment = new PopularFragment(); break; case R.id.writeYourOwn: if (getSupportActionBar() != null) { getSupportActionBar().setTitle(getString(R.string.str_WriteYourOwn)); } qodFavorite.setVisible(false); qodShare.setVisible(false); qodCopy.setVisible(false); wyoDone.setVisible(true); wyoShare.setVisible(true); pqInfo.setVisible(false); fragment = new WriteYourOwnFragment(); break; case R.id.aboutMe: if (getSupportActionBar() != null) { getSupportActionBar().setTitle(getString(R.string.str_AboutMe)); } qodFavorite.setVisible(false); qodShare.setVisible(false); qodCopy.setVisible(false); wyoDone.setVisible(false); wyoShare.setVisible(false); pqInfo.setVisible(false); fragment = new AboutMeFragment(); break; case R.id.credits: if (getSupportActionBar() != null) { getSupportActionBar().setTitle(getString(R.string.str_Credits)); } qodFavorite.setVisible(false); qodShare.setVisible(false); qodCopy.setVisible(false); wyoDone.setVisible(false); wyoShare.setVisible(false); pqInfo.setVisible(false); fragment = new CreditsFragment(); break; case R.id.favoriteQuotes: if (getSupportActionBar() != null) { getSupportActionBar().setTitle(getString(R.string.str_FavoriteQuotes)); } qodFavorite.setVisible(false); qodShare.setVisible(false); qodCopy.setVisible(false); wyoDone.setVisible(false); wyoShare.setVisible(false); pqInfo.setVisible(false); fragment = new FavoriteQuotesFragment(); break; case R.id.settings: if (getSupportActionBar() != null) { getSupportActionBar().setTitle(getString(R.string.str_Settings)); } qodFavorite.setVisible(false); qodShare.setVisible(false); qodCopy.setVisible(false); wyoDone.setVisible(false); wyoShare.setVisible(false); pqInfo.setVisible(false); fragment = new SettingsFragment(); break; } FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.mainFrame, fragment); ft.commit(); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerLayout.closeDrawer(GravityCompat.START); return true; }
From source file:com.example.andres.chatandroid.navigationDrawer.HeaderActivity.java
/** * en este metodo se realiza la actuliacion de los menus y nombres del toolbar cada vez que se cambia de elemento * @param idMenu//from ww w . j a v a 2 s .c o m * @param title * @param subTitle * @param fragment */ public void ActualizarToolbar(int idMenu, final String title, String subTitle, Fragment fragment) { final Fragment fragm = fragment; android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager() .beginTransaction(); fragmentTransaction.replace(R.id.frame, fragment); fragmentTransaction.commit(); toolbar.getMenu().clear(); ActualizarMenu(idMenu); toolbar.setTitle(title); toolbar.setSubtitle(subTitle); toolbar.refreshDrawableState(); toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { //Replacing the main content with ContentFragment Which is our Inbox View; case R.id.action_add: Intent add = new Intent(HeaderActivity.this, Contactos.class); startActivity(add); break; case R.id.action_group: Intent intentgroup = new Intent(HeaderActivity.this, chackListGrupos.class); startActivity(intentgroup); break; case R.id.actualizar: if (title != "Comunidad") { final BlankFragment2 frag = (BlankFragment2) fragm; frag.recargar(); } break; } return true; } }); }
From source file:com.example.android.fragments._3_IncidentDescription.java
@Override public void onClick(View v) { Toast.makeText(this.ll.getContext(), "Das ist das 4. Fragment", Toast.LENGTH_SHORT).show(); if (v.getResources().getResourceName(v.getId()).substring(30).contentEquals("id/descr_finished_button")) { Toast.makeText(this.ll.getContext(), v.getResources().getResourceName(v.getId()), Toast.LENGTH_SHORT) .show();/*from ww w . j a v a2 s . c o m*/ Toast.makeText(this.ll.getContext(), locdescrp.getText(), Toast.LENGTH_SHORT).show(); FragmentTransaction transaction = fragact.getSupportFragmentManager().beginTransaction(); _4_FinalScreen newFragment = new _4_FinalScreen(); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack so the user can navigate back transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null); // Commit the transaction transaction.commit(); } else if (v.getResources().getResourceName(v.getId()).substring(30) .contentEquals("id/detailed_location_description")) { // TODO: 11/15/2016 } else if (v.getResources().getResourceName(v.getId()).substring(30) .contentEquals("id/damage_description_information")) { // TODO: 11/15/2016 } else if (v.getResources().getResourceName(v.getId()).substring(30) .contentEquals("id/facilities_spinner")) { // TODO: 11/15/2016 } }
From source file:com.example.diego.activitytracker.MainActivity.java
public void onArticleSelected(int position, long id) { // The user selected the headline of an article from the HeadlinesFragment // Capture the article fragment from the activity layout ArticleFragment articleFrag = (ArticleFragment) getSupportFragmentManager() .findFragmentById(R.id.article_fragment); if (articleFrag != null) { // If article frag is available, we're in two-pane layout... // Call a method in the ArticleFragment to update its content articleFrag.updateArticleView(position, id); } else {//from w w w . ja va2 s . c o m // If the frag is not available, we're in the one-pane layout and must swap frags... // Create fragment and give it an argument for the selected article ArticleFragment newFragment = new ArticleFragment(); Bundle args = new Bundle(); args.putInt(ArticleFragment.ARG_POSITION, (int) id); newFragment.setArguments(args); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack so the user can navigate back transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null); // Commit the transaction transaction.commit(); } }
From source file:com.example.android.FragmentMain.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View v = inflater.inflate(R.layout.fragment_main, container, false); TextView mTxtTitle = (TextView) v.findViewById(R.id.txtTitle); mTxtTitle.setText(getArguments().getString(TEXT_FRAGMENT)); ereceipt = (ToggleButton) v.findViewById(R.id.ToggleButton1); ereceipt.setOnClickListener(new OnClickListener() { @Override/* w w w. j a v a 2 s.c o m*/ public void onClick(View v) { if (!ereceipt.isChecked()) { cancel_payment.setChecked(true); reprint.setChecked(true); list_of_collections.setChecked(true); more.setChecked(true); settings.setChecked(true); Fragment_Blank_Space(); Fragment_eReceipt er = new Fragment_eReceipt(); FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.layoutToReplace, er); ft.commit(); } else { Fragment_Blank_Space(); } } }); list_of_collections = (ToggleButton) v.findViewById(R.id.ToggleButton2); list_of_collections.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!list_of_collections.isChecked()) { ereceipt.setChecked(true); cancel_payment.setChecked(true); reprint.setChecked(true); list_of_collections.setChecked(false); more.setChecked(true); settings.setChecked(true); Fragment_Blank_Space(); Fragment_List_Of_Collections loc = new Fragment_List_Of_Collections(); FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.layoutToReplace, loc); ft.commit(); } else { Fragment_Blank_Space(); } } }); reprint = (ToggleButton) v.findViewById(R.id.ToggleButton3); reprint.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!reprint.isChecked()) { Toast t3 = Toast.makeText(v.getContext(), "Reprint", Toast.LENGTH_SHORT); t3.show(); reprint.setChecked(false); cancel_payment.setChecked(true); ereceipt.setChecked(true); list_of_collections.setChecked(true); more.setChecked(true); settings.setChecked(true); Fragment_Blank_Space(); } } }); cancel_payment = (ToggleButton) v.findViewById(R.id.ToggleButton4); cancel_payment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast t4 = Toast.makeText(v.getContext(), "Cancel Payment", Toast.LENGTH_SHORT); t4.show(); if (!cancel_payment.isChecked()) { cancel_payment.setChecked(false); reprint.setChecked(true); ereceipt.setChecked(true); list_of_collections.setChecked(true); more.setChecked(true); settings.setChecked(true); Fragment_Blank_Space(); } } }); settings = (ToggleButton) v.findViewById(R.id.ToggleButton5); settings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast t5 = Toast.makeText(v.getContext(), "Settings", Toast.LENGTH_SHORT); t5.show(); if (!settings.isChecked()) { settings.setChecked(false); cancel_payment.setChecked(true); reprint.setChecked(true); ereceipt.setChecked(true); list_of_collections.setChecked(true); more.setChecked(true); Fragment_Blank_Space(); } } }); more = (ToggleButton) v.findViewById(R.id.ToggleButton6); more.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast t6 = Toast.makeText(v.getContext(), "More", Toast.LENGTH_SHORT); t6.show(); if (!more.isChecked()) { more.setChecked(false); cancel_payment.setChecked(true); reprint.setChecked(true); ereceipt.setChecked(true); list_of_collections.setChecked(true); settings.setChecked(true); Fragment_Blank_Space(); } } }); v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); return v; }
From source file:com.example.d062654.faciliman.XYZ.java
@Override public void onClick(View v) { Toast.makeText(this.ll.getContext(), "Das ist das dritte Fragment", Toast.LENGTH_SHORT).show(); Toast.makeText(this.ll.getContext(), v.getResources().getResourceName(v.getId()), Toast.LENGTH_SHORT) .show();/*from w ww . j a v a 2 s.co m*/ FragmentTransaction transaction = fragact.getSupportFragmentManager().beginTransaction(); _3_IncidentDescription newFragment = new _3_IncidentDescription(); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack so the user can navigate back transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null); // Commit the transaction transaction.commit(); /*if(v.getResources().getResourceName(v.getId()).substring(30).contentEquals("id/damagebutton")){ Toast.makeText(this.ll.getContext(), v.getResources().getResourceName(v.getId()), Toast.LENGTH_SHORT).show(); FragmentTransaction transaction = fragact.getSupportFragmentManager().beginTransaction(); _3_IncidentDescription newFragment = new _3_IncidentDescription(); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack so the user can navigate back transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null); // Commit the transaction transaction.commit(); } else if(v.getResources().getResourceName(v.getId()).substring(30).contentEquals("id/othersbutton")){ // TODO: 11/15/2016 } else if(v.getResources().getResourceName(v.getId()).substring(30).contentEquals("id/pollutionbutton")){ // TODO: 11/15/2016 } else if(v.getResources().getResourceName(v.getId()).substring(30).contentEquals("id/missingequipmentbutton")){ // TODO: 11/15/2016 }*/ }
From source file:com.business.rushour.businessapp.RiderMainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ridermain); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*w w w.j av a 2s .c om*/ uploadphoto = (CircularImageView) findViewById(R.id.CircularImageViews); 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); View header = navigationView.getHeaderView(0); header.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { captureImage(); } }); RiderMainFragmentClass fragment = new RiderMainFragmentClass(); android.support.v4.app.FragmentTransaction fm = getSupportFragmentManager().beginTransaction(); fm.replace(R.id.content_frame, fragment); fm.commit(); }
From source file:com.audiokernel.euphonyrmt.library.SimpleLibraryActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.library_tabs); final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); mTitleView = (TextView) inflater.inflate(R.layout.actionbar_title, null); mTitleView.setFocusable(true);/*from w w w . j a va 2 s .com*/ mTitleView.setFocusableInTouchMode(true); mTitleView.setSelected(true); mTitleView.requestFocus(); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setCustomView(mTitleView); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayShowCustomEnabled(true); } if (savedInstanceState == null) { final Fragment rootFragment = getRootFragment(); if (rootFragment == null) { throw new RuntimeException("Error : SimpleLibraryActivity root fragment is null"); } if (rootFragment instanceof BrowseFragment) { setTitle(((BrowseFragment) rootFragment).getTitle()); } final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.replace(R.id.root_frame, rootFragment); ft.commit(); } else { refreshTitleFromCurrentFragment(); } getSupportFragmentManager().addOnBackStackChangedListener(this); }
From source file:com.business.rushour.businessapp.RiderMainActivity.java
private void displaySelectedScreen(int itemId) { //creating fragment object Fragment fragment = null;/* www .ja v a2s. c om*/ //initializing the fragment object which is selected switch (itemId) { case R.id.postride: postride(); break; case R.id.trackride: Intent login = new Intent(this, NavigationTrackRideActivity.class); startActivity(login); break; case R.id.history: Intent history = new Intent(this, NavigationHistoryActivity.class); startActivity(history); break; case R.id.wallet: Intent wallet = new Intent(this, NavigationWalletActivity.class); startActivity(wallet); break; case R.id.profile: Intent profile = new Intent(this, NavigationProfileActivity.class); startActivity(profile); break; case R.id.aboutus: Intent aboutus = new Intent(this, NavigationAboutUsActivity.class); startActivity(aboutus); break; case R.id.contactus: Intent contactus = new Intent(this, NavigationContactUsActivity.class); startActivity(contactus); break; case R.id.tc: Intent tc = new Intent(this, NavigationTermsConditionsActivity.class); startActivity(tc); break; case R.id.logout: Intent logout = new Intent(this, NavigationLogoutActivity.class); startActivity(logout); break; } //replacing the fragment if (fragment != null) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.content_frame, fragment); ft.commit(); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); }
From source file:com.example.parking.ParkingSpaceDetailActivity.java
private void changeFragment(int resId) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();//?Fragment hideFragments(transaction);//??fragment if (resId == R.id.parkingInformation) { mParkingInformationFragment = new ParkingInformationFragment(); transaction.replace(R.id.parking_container, mParkingInformationFragment); /* if(mParkingInformationFragment==null){//?.? mParkingInformationFragment = new ParkingInformationFragment(); transaction.add(R.id.parking_container,mParkingInformationFragment); }else { /*from w w w .ja v a2s . c om*/ transaction.replace(R.id.parking_container, mParkingInformationFragment); }*/ } else if (resId == R.id.recordOfToday) { mTodayRecordFragment = new TodayRecordFragment(); transaction.replace(R.id.parking_container, mTodayRecordFragment); /*if(mTodayRecordFragment==null){//?.? mTodayRecordFragment = new TodayRecordFragment(); transaction.add(R.id.parking_container,mTodayRecordFragment); }else { transaction.show(mTodayRecordFragment); }*/ } transaction.commit();//??? }