@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cb1 = (CheckBox) findViewById(R.id.checkbox1);
cb2 = (CheckBox) findViewById(R.id.checkbox2);
tv = (TextView) findViewById(R.id.textview1);
cb1.setOnCheckedChangeListener(cb);
cb2.setOnCheckedChangeListener(cb);
}
private CheckBox.OnCheckedChangeListener cb = new CheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
String stv = getString(R.string.hoby);
String scb1 = getString(R.string.basketball);
String scb2 = getString(R.string.football);
if (cb1.isChecked() && cb2.isChecked()) {
tv.setText(stv + ":" + scb1 + "&&" + scb2);
} else if (cb1.isChecked() && !cb2.isChecked()) {
tv.setText(stv + ":" + scb1);
} else if (!cb1.isChecked() && cb2.isChecked()) {
tv.setText(stv + ":" + scb2);
} else {
tv.setText(stv);
}
}
};
android:layout_
android:layout_
android:orientation="vertical" >
android:id="@+id/textview1" android:layout_ android:layout_ android:text="@string/hoby" /> android:id="@+id/checkbox1" android:layout_ android:layout_ android:text="@string/basketball" /> android:id="@+id/checkbox2" android:layout_ android:layout_ android:text="@string/football" />