Previous fragment visible under the new fragment issue
-
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
-
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
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