Code example for ToggleButton

Methods: setChecked, isChecked, setOnCheckedChangeListener

0
	/** 
	 * 	setupListeners 
	 */ 
	private void setupListeners() { 
		nameET.setOnEditorActionListener(this);
		powerTB.setOnCheckedChangeListener(this);
		tempET.setOnEditorActionListener(this);
		saveButton.setOnClickListener(this);
	} 
 
	/** 
	 * 	setupWidets 
	 */ 
	private void setupWidgets() { 
		pageTitle.setText("Oven");
		nameET.setText(oven.getName());
		powerTB.setChecked(oven.isOn());
		tempET.setText(String.valueOf(oven.getTemp()));
		 
		pageTime.setText(DateFormat.getDateInstance().format(new Date()));
		leftButton.setVisibility(View.GONE);
		rightButton.setVisibility(View.GONE);
		 
		staleName = oven.getName();
		stalePower = oven.isOn();
		staleTemp = oven.getTemp();
	} 
	 
	/** 
	 * 	changeSaveButtonState 
	 */ 
	public void changeSaveButtonState() { 
		if (staleName.equals(nameET.getText().toString()) &&
				stalePower == powerTB.isChecked() &&
				staleTemp == Double.valueOf((tempET.getText().toString()))) {
			saveButton.setEnabled(false);
		} else { 
			saveButton.setEnabled(true);
		} 
		 
		if (!powerTB.isChecked())
			tempET.setEnabled(false);
		else 
			tempET.setEnabled(true);
	}