package app.test;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
public class Test extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
CheckBox fishCB = (CheckBox) findViewById(R.id.fishCB);
if (fishCB.isChecked())
fishCB.toggle();
fishCB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
Log.v("CheckBoxActivity", (isChecked ? "checked" : "not checked"));
}
});
}
public void doClick(View view) {
Log.v("CheckBoxActivity", ((CheckBox) view).isChecked() ? "checked" : "not checked");
}
}
//main.xml
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_width="wrap_content" android:layout_height="wrap_content" />
android:layout_width="wrap_content" android:layout_height="wrap_content" />
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:onClick="doClick" />