I am developing a small app that will show me a Toast when I click on a button.
The problem is that I run the normal app but it does not show me the toast and it does not throw me an error either, it's as if I had not put it. I would appreciate the help of someone thanks.
public class MainActivity extends AppCompatActivity {
CheckBox c1;
CheckBox c2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
c1=(CheckBox) findViewById(R.id.idcheck1);
c2= (CheckBox) findViewById(R.id.idcheck2);
}
public void onClick(View view){
if(view.getId()==R.id.btn1){
validar();
}
}
private void validar(){
String cad="Seleccionado:\n";
if (c1.isChecked()==true){
cad+="Opcion 1";
}
if(c2.isChecked()==true){
cad+="Opcion 2";
}
Toast.makeText(getApplicationContext(),cad , Toast.LENGTH_SHORT).show();
}
}