lundi 10 août 2015

Java AndroidStudio Trying to show a message after checking a box

I am pretty new to java so I tried to do something simple, to show a message when a checkBox is checked. I got an error and I have no idea why, here is the code:

public class MainActivity extends AppCompatActivity {

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




Aucun commentaire:

Enregistrer un commentaire