Back to project page androidui.
The source code is released under:
MIT License
If you think the Android project androidui listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package course.examples.UI.CheckBox; /*from w w w . j a va 2 s . c om*/ import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; public class CheckBoxActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Get a reference to the CheckBox final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox); // Set an OnClickListener on the CheckBox checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { // Check whether CheckBox is currently checked // Set CheckBox text accordingly if (isChecked) { checkbox.setText("I'm checked"); } else { checkbox.setText("I'm not checked"); } } }); // Get a reference to the Hide CheckBox Button final Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Toggle the CheckBox's visibility state // Set the Button text accordingly if (checkbox.isShown()) { checkbox.setVisibility(View.INVISIBLE); button.setText("Unhide CheckBox"); } else { checkbox.setVisibility(View.VISIBLE); button.setText("Hide CheckBox"); } } }); } }