mardi 11 août 2015

AndroidStudio Java Message after checking a box

I am trying to display a message when I check a box. The problem is that the message is not shown. If I start the application with the box checked by default, the message will just be shown at the beginning and if I try to uncheck and check again, it won't appear again. Here is the code:

public class MainActivity extends AppCompatActivity {

CheckBox checkBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    checkBox = (CheckBox) findViewById(R.id.checkBox);
    if (checkBox.isChecked())
        Toast.makeText(MainActivity.this, "Box was checked", Toast.LENGTH_SHORT).show();
}




Aucun commentaire:

Enregistrer un commentaire