Code example for ToggleButton

Methods: setChecked, refreshDrawableState

0
	private void setIcon() { 
		/* 
		 * Draw icon 
		 */ 
		if (PrefUtil.readBoolean(getActivity(), Pref.LOG_KEY.key())) {
			logToggle.setChecked(true);
		} else { 
			logToggle.setChecked(false);
		} 
		logToggle.refreshDrawableState();
	} 
 
	@Override 
	public void onPause() { 
		/* 
		 * Set pref so LogService can send log lines to the broadcastreceiver 
		 */ 
		if (getActivity() != null)
			PrefUtil.writeBoolean(this.getActivity(), HAS_LOGFRAGMENT, false);
		unregisterReceiver(); 
		super.onPause(); 
	} 
 
	@Override 
	public void onResume() { 
		if (getActivity() != null) {
			PrefUtil.writeBoolean(this.getActivity(), HAS_LOGFRAGMENT, true);
			logToggle.setChecked(PrefUtil.readBoolean(this.getActivity(),
					Pref.LOG_KEY.name())); 
			registerReceiver(); 
			setIcon(); 
		} 
		mySV.post(new ScrollToBottom());