<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="唱歌"
android:id="@+id/checkBox"
/>
public class MainActivity extends ActionBarActivity {
private CheckBox checkBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkBox = (CheckBox) findViewById(R.id.checkBox);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
String text = checkBox.getText().toString();
Log.i("tag",text);
Toast.makeText(MainActivity.this,text,Toast.LENGTH_SHORT).show();
}
}
});
}
}