Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. Previous fragment visible under the new fragment issue

Previous fragment visible under the new fragment issue

Scheduled Pinned Locked Moved Android
helpandroidcombeta-testingxml
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pavlex4
    wrote on last edited by
    #1

    I have created android application with navigation drawer and when I click item from navigation drawer old fragment is not replaced,I can still see the old fragment under the new fragment.How to fix this issue?

    private void displaySelectedScreen(int id)
    {
    Fragment fragment = null;

            switch (id)
            {
                case R.id.home:
                    fragment = new Main();
                    break;
                case R.id.settings:
                    Intent intent = new Intent(this, Settings.class);
                    startActivity(intent);
                    break;
                case R.id.about:
                    Intent intent1 = new Intent(this, About.class);
                    startActivity(intent1);
                    break;
                case R.id.share:
                    try
                    {
                        Intent i = new Intent(Intent.ACTION\_SEND);
                        i.setType("text/plain");
                        i.putExtra(Intent.EXTRA\_SUBJECT, "Audiophileradio");
                        String sAux = "\\nLet me recommend you this application\\n\\n";
                        sAux = sAux + "https://play.google.com/store/apps/details?id=Orion.Soft \\n\\n";
                        i.putExtra(Intent.EXTRA\_TEXT, sAux);
                        startActivity(Intent.createChooser(i, "choose one"));
                    }
                    catch(Exception e)
                    {
                        //e.toString();
                    }
                    break;
                case R.id.send:
                    fragment = new Feedback();
                    break;
            }
            if (fragment != null)
            {
                FragmentManager fragmentManager = getSupportFragmentManager();
                fragmentManager.beginTransaction()
                        .replace(R.id.contentFrame, fragment).commit();
            }
    
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer\_layout);
            drawer.closeDrawer(GravityCompat.START);
        }
    
        @SuppressWarnings("StatementWithEmptyBody")
        @Override
        public boolean onNavigationItemSelected(MenuItem item)
        {
            // Handle navigation view item clicks here.
            int id = item.getItemId();
    
            displaySelectedScreen(id);
    
            return true;
        }
    

    content_main.xml

    D 1 Reply Last reply
    0
    • P Pavlex4

      I have created android application with navigation drawer and when I click item from navigation drawer old fragment is not replaced,I can still see the old fragment under the new fragment.How to fix this issue?

      private void displaySelectedScreen(int id)
      {
      Fragment fragment = null;

              switch (id)
              {
                  case R.id.home:
                      fragment = new Main();
                      break;
                  case R.id.settings:
                      Intent intent = new Intent(this, Settings.class);
                      startActivity(intent);
                      break;
                  case R.id.about:
                      Intent intent1 = new Intent(this, About.class);
                      startActivity(intent1);
                      break;
                  case R.id.share:
                      try
                      {
                          Intent i = new Intent(Intent.ACTION\_SEND);
                          i.setType("text/plain");
                          i.putExtra(Intent.EXTRA\_SUBJECT, "Audiophileradio");
                          String sAux = "\\nLet me recommend you this application\\n\\n";
                          sAux = sAux + "https://play.google.com/store/apps/details?id=Orion.Soft \\n\\n";
                          i.putExtra(Intent.EXTRA\_TEXT, sAux);
                          startActivity(Intent.createChooser(i, "choose one"));
                      }
                      catch(Exception e)
                      {
                          //e.toString();
                      }
                      break;
                  case R.id.send:
                      fragment = new Feedback();
                      break;
              }
              if (fragment != null)
              {
                  FragmentManager fragmentManager = getSupportFragmentManager();
                  fragmentManager.beginTransaction()
                          .replace(R.id.contentFrame, fragment).commit();
              }
      
              DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer\_layout);
              drawer.closeDrawer(GravityCompat.START);
          }
      
          @SuppressWarnings("StatementWithEmptyBody")
          @Override
          public boolean onNavigationItemSelected(MenuItem item)
          {
              // Handle navigation view item clicks here.
              int id = item.getItemId();
      
              displaySelectedScreen(id);
      
              return true;
          }
      

      content_main.xml

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      See here.

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups