The problem is the following I have my main activiy that consists of a drawer activity when I give some of the options of the drawer activity I have to pass to a fragment, the problem is the following when I pass to the fragment I lose the option to open the menu From the drawer from the fragment
`
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.design.widget.NavigationView;
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.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar 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);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);`
This is the main activity java code
This is the fragment code where I want to implement the drawer
public class Fragmen1 extends Fragment {
Button HBoton;
Button GBoton;
Button SCTBoton ;
Button RGboton ;
Button CPBoton ;
Button ARBoton;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_fragmen1, container, false);
HBoton = (Button) view.findViewById(R.id.HipotenusaBoton);
HBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent HBoton = new Intent(getActivity(), Hipotenusa.class);
startActivity(HBoton);
}
});
GBoton= (Button) view.findViewById(R.id.button3);
GBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent GBoton = new Intent(getActivity(), Grados_Radianes.class);
startActivity(GBoton);
}
});
SCTBoton = (Button) view.findViewById(R.id.SCTboton);
SCTBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View v ){
Intent SCTBoton = new Intent(getActivity(), SenoCosenoTangente.class);
startActivity(SCTBoton);
}
});
RGboton = (Button) view.findViewById(R.id.button6);
RGboton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent RGboton = new Intent(getActivity(),RadianesGrados.class);
startActivity(RGboton);
}
});
CPBoton = (Button) view.findViewById(R.id.CAPbutton);
CPBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent CPBoton = new Intent( getActivity(),CordenadasRectagularesPolares.class);
startActivity(CPBoton);
}
});
ARBoton = (Button) view.findViewById(R.id.arboton);
ARBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent ARBoton = new Intent( getActivity(),AnguloReferencia.class);
startActivity(ARBoton);
}
});
return view;
}
}