title: How to make an ImageButton visible/invisibl
body: <p>I'm trying to create an imagebutton to close an ad from admob.
  I've created the button in the xml with the visibility property set to "invisible" and then on java I set it to "visible" when the ad is received, but the button never become visible.
  If I set it to "visible" hardcoded on the XML it appears on the screen normally.</p>
  
  <p>Admob layout:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:id="@+id/layout_main"&gt;
      &lt;ImageButton        
          android:id="@+id/close_ad"
          android:visibility="invisible"
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_gravity="right"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="-36dip"
          android:layout_marginTop="12dip"
          android:background="@drawable/btn_close_ad" /&gt;  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Add ad:</p>
  
  <pre><code>private void addAd() {
      rl = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.admob, null);
      rl.setGravity(position);
      activity.addContentView(rl, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
      AdView admobView = new AdView(activity, AdSize.BANNER, Preferences.getAdmobKey());
      admobView.loadAd(new AdRequest());
      [ ... ]
      admobView.setAdListener(new AdListener() {
      @Override
      public void onReceiveAd(Ad ad) {
          Log.v("JeraAdmob", "onReceiveAd");
          new Handler().postDelayed(new Runnable() {
              @Override
              public void run() {
                  createCloseButton();
              }
          }, AD_SHOW_CLOSE);
      }
      });
  }
  </code></pre>
  
  <p>Create button to close the ad:</p>
  
  <pre><code>private void createCloseButton() {
          ImageButton button = (ImageButton) rl.findViewById(R.id.close_ad);
          button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  rl.removeAllViews();
                  handler.postDelayed(new Runnable() {
                      @Override
                      public void run() {
                          addAd();
                          rl.bringToFront();
                      }
                  }, AD_RELOAD);
              }
          });
          button.setVisibility(View.VISIBLE);
          button.bringToFront();
      }
  </code></pre>