Navigation Drawer without interaction when clicked

2

I'm using the default menu Navigation Drawer and have completed the method that already comes in the project to open my activities(Atividades) . I have already created the classes and I have already called each of them according to the image below, but when I click on a menu item, it does not change the windows.

Andhere'soneofmyclasses:

publicclassSecondActivityextendsAppCompatActivity{privateButtonshare;privateToolbarmToolbar;privateToolbarmToolbarBottom;privateButtonaction_settings;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_second);mToolbarBottom=(Toolbar)findViewById(R.id.inc_tb_bottom);mToolbarBottom.setOnMenuItemClickListener(newToolbar.OnMenuItemClickListener(){@OverridepublicbooleanonMenuItemClick(MenuItemmenuItem){Intentit=null;switch(menuItem.getItemId()){caseR.id.action_facebook:it=newIntent(Intent.ACTION_VIEW);it.setData(Uri.parse("https://www.facebook.com/PrefeituraMunicipalDeJaguaruana"));
                    break;
                case R.id.action_youtube:
                    it = new Intent(Intent.ACTION_VIEW);
                    it.setData(Uri.parse("http://www.jaguaruana.ce.gov.br/"));

            }

            startActivity(it);
            return true;
        }
    });
    mToolbarBottom.inflateMenu(R.menu.menu_bottom);

    /*mToolbarBottom.findViewById(R.id.iv_settings).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(SecondActivity.this, "Settings pressed", Toast.LENGTH_SHORT).show();
        }*/

}


@Override
protected void onResume() {
    super.onResume();

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
        mToolbar.setBackgroundResource(R.drawable.toolbar_rounded_corners);
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_second, menu);
    return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if(id == android.R.id.home){
        finish();
    }

    return true;
}
    
asked by anonymous 04.06.2016 / 18:47

1 answer

1

To call up a new Activity:

Create a new Activity with the name of MainActivity2 and enter this code below in your onNavigationItemSelected method of your MainActivity :

Intent intent = new Intent(this, MainActivity2.class); 
startActivity(intent);

To call a new Fragment:

Create a new Fragment with the name of novoFragment and enter this code below in your onNavigationItemSelected method of your MainActivity :

novoFragment fragment = new novoFragment();
android.support.v4.app.FragmentTransaction fragmentTrasaction =
getSupportFragmentManager().beginTransaction();
fragmentTrasaction.replace(R.id.fragment_container, fragment);
fragmentTrasaction.commit();

** Important Notice **

In order for this fragment call to complete successfully (work), you need to follow this most complete post on the subject: 3-point menu in all Activities with the default Navigation Drawer

In your MainActivity - Solution in Practice:

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_camera) {
        // abrindo um novo fragment
     novoFragment fragment = new novoFragment();
    android.support.v4.app.FragmentTransaction fragmentTrasaction =
    getSupportFragmentManager().beginTransaction();
    fragmentTrasaction.replace(R.id.fragment_container, fragment);
    fragmentTrasaction.commit();
    } else if (id == R.id.nav_gallery)  {
    // abrindo um nova activity
    Intent intent = new Intent(this, MainActivity2.class); 
    startActivity(intent);    
    } else if (id == R.id.nav_slideshow) {

    } else if (id == R.id.nav_manage) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
    
04.06.2016 / 19:14