title: Android - Show/Hide imageView with ToggleButton
body: <p>I am trying to hide/show an imageView by using a toggleButton, but it does not work.
  Here is my code of the related parts:<br/>
  XML:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity" &gt;
  
      &lt;Switch
      android:id="@+id/toggleButton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentRight="true"
      android:layout_alignParentTop="true"
      android:textOff="auto"
      android:textOn="manuel" /&gt;
  
      &lt;ImageView
      android:id="@+id/compass"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:src="@drawable/compass" /&gt;
  
      &lt;ImageView
      android:id="@+id/compass_direction"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:src="@drawable/compass_direction"
      android:rotation="180" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And here the JAVA-part:</p>
  
  <pre><code>public class SnowActivity extends MenuActivity implements SensorEventListener,
      OnCheckedChangeListener, OnTouchListener, ScrollViewListener {
  
      private Switch toggleButton;
      private ImageView compass;
      private ImageView compass_direction;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_snow);
  
      toggleButton = (Switch) findViewById(R.id.toggleButton);
      toggleButton.setOnCheckedChangeListener(this);
  
      compass = (ImageView) findViewById(R.id.compass);
      compass_direction = (ImageView) findViewById(R.id.compass_direction);
      }
  
      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      sensorEnabled = !isChecked;
      if (sensorEnabled) {
          compass.setVisibility(View.VISIBLE);
          compass_direction.setVisibility(View.VISIBLE);
      } else {
          compass.setVisibility(View.INVISIBLE);
          compass_direction.setVisibility(View.INVISIBLE);
      }
  }
  }
  </code></pre>
  
  <p>If I manually add the visible tag on the imageView in xml with</p>
  
  <pre><code>android:visibility = "visible"
  </code></pre>
  
  <p>it's working. At least the pics are hidden in the 'Graphical Layout', but programmatically it doesn't. Besides I also have additional methods which are called in the onCheckedChange() method, so the ToggleButton seems to be implemented correctly.</p>
  
  <p>Thanks in advance!
  Greetings.</p>