How do I make drawer layout buttons take me to another screen? I tried this way but it did not work Something else, when I click on the drawer's menu, it looks like it's just a text, not that click effect, I'll leave my entire MainActivity below
@SuppressWarnings("StatementWithEmptyBody")
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.testando) {
Button button = (Button) findViewById(R.id.testando);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it= new Intent(MainActivity.this,
Ingredientes.class);
}
});
MainActivity Integer
import android.content.Intent;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Toolbar toolbar;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
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);
toggle.syncState();
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@SuppressWarnings("StatementWithEmptyBody")
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.testando) {
Button button = (Button) findViewById(R.id.testando);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it= new Intent(MainActivity.this, Ingredientes.class);
}
});
} else if (id == R.id.passo1) {
} else if (id == R.id.passo2) {
} else if (id == R.id.passo3) {
} else if (id == R.id.passo4) {
} else if (id == R.id.passo5) {
} else if (id == R.id.passo6) {
} else if (id == R.id.passo7) {
} else if (id == R.id.passo8) {
} else if (id == R.id.donate) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}