hola que tal quisiera saber por que mi fragmento no funciona cada que le presiono en el menu deslizable
Por ejemplo este es el codigo de mi fragment:
public class frg extends Fragment implements View.OnClickListener { TextView ms, alt, to, cim; Button aceptar; 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){
}
}
}
y aqui es donde lo mando a llamar en el codigo del menu deslizable:
@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;
}
}