Android is an open-source mobile phone operating system launched by Google based on the Linux platform. We once introduced the system architecture of this system in the previous article. I believe you can have a preliminary understanding of this system. Here, you can fully understand the basic concepts of the Android check box.
- Android 2.1 AIDS Nexus One vs. iPhone
- Google Android: survival or extinction
- MOTO released Android app store for China
- Android simulators correct application and installation methods
- Analysis of the basic architecture mode of Android
● Call the setChecked () method when setting the Check status of the Check box.
● When the append Android check box is selected,
1. Call the setOnCheckedChangeListener () method and pass the CompoundButton. OnCheckedChangeListener instance as a parameter.
2. In the onCheckedChanged () method of CompoundButton. OnCheckedChangeListener, obtain the instance of the selected Android check box.
Routine source code (Java)
- CheckBox checkBox = (CheckBox) findViewById(id.checkBox);
- checkBox.setChecked(true);
- checkBox.setOnCheckedChangeListener(
- new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(
- CompoundButton buttonView,
- boolean isChecked) {
- CheckBox checkBox = (CheckBox) buttonView;
- Log.v("Test", String.valueOf(checkBox.getText()) +
- " is " + String.valueOf(isChecked));
- }
- });
Routine source code (Resource)
- < CheckBox android:id="@+id/checkBox"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/test" />
The basic application of the Android check box is introduced here.