Android: Haz que aparezca una tostada en el botón, haz clic en
Soy bastante nuevo en Android y me estoy familiarizando con las cosas comunes, pero no puedo entender el onClickListner (); Básicamente tengo dos casillas de verificación y un botón y al hacer clic en un botón, debería aparecer una tostada y decir qué casillas están marcadas y cuáles no.
public class ExActivity extends Activity implements View.OnClickListener {
CheckBox cb;
CheckBox cb2;
Button buton;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cb=(CheckBox) findViewById(R.id.cb);
cb2=(CheckBox) findViewById(R.id.checkbox);
buton = (Button)findViewById(R.id.buton);
buton.setOnClickListener(this);
}
public void onClick(View arg0) {
Toast toast;
if(cb.isChecked()&&cb2.isChecked()) toast = Toast.makeText(getApplicationContext(), "Amandoua sunt bifate", Toast.LENGTH_SHORT);
else if(cb.isChecked()&&!cb2.isChecked()) toast = Toast.makeText(getApplicationContext(), "Doar prima e bifata", Toast.LENGTH_SHORT);
else if(!cb.isChecked()&&cb2.isChecked()) toast = Toast.makeText(getApplicationContext(), "Doar a doua e bifata", Toast.LENGTH_SHORT);
else if(!cb.isChecked()&&!cb2.isChecked()) toast = Toast.makeText(getApplicationContext(), "Nici una nu e bifata", Toast.LENGTH_SHORT);
}
}
Desprecie los nombres y textos de variables rumanas y el XML está bien. También intenté agregar onClick () de esta manera:
buton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// my code;
}
});
pero este es aún peor. ¿Ayuda