package course.examples.UI.ToggleButton;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.ToggleButton;

public class ToggleButtonActivity extends Activity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		final LinearLayout bg = (LinearLayout) findViewById(R.id.linearlayout);
		
		final ToggleButton button = (ToggleButton) findViewById(R.id.togglebutton);
		button.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (button.isChecked()) {
					bg.setBackgroundColor(0xFFF3F3F3);
				} else {
					bg.setBackgroundColor(0xFF000000);
				}
			}
		});
		
	}
}

@@ -418,16 +418,64 @@
 main);%0A%0A
+%09%09// Get a reference to a background container %0A
 %09%09final 
@@ -543,16 +543,57 @@
 ut);%0A%09%09%0A
+%09%09// Get a reference to the ToggleButton%0A
 %09%09final 
@@ -662,16 +662,67 @@
 utton);%0A
+%09%09%0A%09%09// Set an OnClickListener on the ToggleButton%0A
 %09%09button
@@ -807,24 +807,95 @@
 k(View v) %7B%0A
+%09%09%09%09%0A%09%09%09%09// Toggle the Background color between a light and dark color%0A
 %09%09%09%09if (butt

update comments