title: Last place to set visibility of a child view
body: <p>I am using Android APi 3.
  I built a container control that contains two controls: another container (layout) and a ListView.</p>
  
  <p>In the main container control, I overrode onLayout function to change visibility of a child view to GONE / VISIBLE depending on items in the list control (2nd child view).</p>
  
  <p>Problem is, when I use GONE and then an event triggers and set it to VISIBLE, the first child control shows but then ListView doesn't show the item - ListView clearly has one item.</p>
  
  <p>Perhaps onLayout may not be the last place to call setVisibility of child controls.  If not, what is the best place?</p>
  
  <p>For my problem, using INVISIBLE fixes problem instead of GONE.</p>
  
  <p>below is the code:
      @Override
      protected void onLayout(boolean changed, int l, int t, int r, int b) {</p>
  
  <pre><code>    /* if there's no data to display, hide headerView */
      if (listView.getAdapter() == null || listView.getAdapter().getCount() == 0)
          headerView.setVisibility(INVISIBLE); // if set to GONE, it won't display the listView when there's only one item or unless it's refreshed 2nd time.
      else
          headerView.setVisibility(VISIBLE);
  
      super.onLayout(changed, l, t, r, b);
  }
  </code></pre>
  
  <p>Any thoughts?</p>