Why does not my fragment work in my slide menu?

0

Hello, I would like to know why my fragment does not work every time I press it in the sliding menu

For example this is the code of my fragment:

public class frg extends Fragment implements View.OnClickListener {     TextView ms, alt, to, cim;     Button accept;     EditText m, a;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {




    // Inflate the layout for this fragment
    View v=inflater.inflate(R.layout.fragment_frg, container, false);
    aceptar=(Button)getView().findViewById(R.id.okey);
    ms=(TextView)getView().findViewById(R.id.etm);
    alt=(TextView)getView().findViewById(R.id.eta);
    to=(TextView)getView().findViewById(R.id.etiqueta);
    m=(EditText) getView().findViewById(R.id.masa);
    a=(EditText)getView().findViewById(R.id.altura);
    cim=(TextView)getView().findViewById(R.id.imc);
    aceptar.setOnClickListener(this);
    return  v;



}

@Override
public void onClick(View v) {
    try{
            switch (v.getId()){

                case R.id.okey:
                double total, m1, a1;
                String txt=m.getText().toString();
                String tx2=a.getText().toString();

                m1=Double.parseDouble(txt);
                a1=Double.parseDouble(tx2);

                total=m1/(a1*a1);
                to.setText(""+total);

                if (total>=1.69){
                    cim.setText("Estas bien pinche gordo :v");
                }

                break;
            }


        } catch (Exception e){

    }
}

}

and here is where I send it to call in the code of the sliding menu:

@Override     public boolean onOptionsItemSelected (MenuItem item) {         // Handle action bar item clicks here. The action bar will         // automatically handle clicks on the Home / Up button, so long         // as you specify a parent activity in AndroidManifest.xml.         int id = item.getItemId ();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    android.support.v4.app.FragmentManager f1 = getSupportFragmentManager();
    if (id == R.id.nav_camera) {
        f1.beginTransaction().replace(R.id.fondito, new frg()).commit();
    } else if (id == R.id.nav_gallery) {

    } 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;
}

}

    
asked by diiego juarez 19.04.2018 в 06:13
source

0 answers