Posted By

uthopiko on 02/18/14


Tagged

android


Versions (?)

1 option


 / Published in: Java
 

First Option for onIconSelect

  1. @Override
  2. public void onIconSelect(String fragmentName) {
  3.  
  4. Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.content_layout);
  5.  
  6. Fragment newFragment = null;
  7.  
  8. if (fragmentName == "Content") {
  9. newFragment = new ContentFragment();
  10. }
  11. else if (fragmentName == "Gallery") {
  12. newFragment = new GalleryFragment();
  13. }
  14. else if (fragmentName == "Location") {
  15. newFragment = new LocationFragment();
  16. }
  17.  
  18. FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
  19.  
  20. if (currentFragment == null) {
  21. transaction.add(R.id.content_layout, newFragment);
  22. } else {
  23. transaction.remove(currentFragment).add(R.id.content_layout, newFragment);
  24. }
  25.  
  26. transaction.addToBackStack(null);
  27. transaction.commit();
  28.  
  29. }

Report this snippet  

You need to login to post a comment.