title: How to get the final height of a Linearlayout which is populated later with addView()
body: <p>I have a LinearLayout to which i populated other views using addview(); but when i try to get the height of the Linear layout, it returns 0.</p>
  
  <p>I used  <code>((LinearLayout)findViewById(R.id.linearId)).getHeight();</code></p>
  
  <p>view i am adding, also has child views. How do i get the height of the Linearlayout including all the children?</p>
  
  <p>EDIT - </p>
  
  <p>actual code i used to adding view to my linear layout - </p>
  
  <pre><code>final ViewTreeObserver viewTreeObserver = earningsContainer.getViewTreeObserver();
          viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
              public void onGlobalLayout() {
                  // read height with myLinearLayout.getHeight() etc.
                  Log.e(TAG, "$$$$$height "+earningsContainer.getHeight());
                  // remember to remove the listener if possible
                  if (viewTreeObserver.isAlive()) {
                      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.JELLY_BEAN) {
                          viewTreeObserver.removeOnGlobalLayoutListener(this);
                      } else {
                          viewTreeObserver.removeGlobalOnLayoutListener(this);
                      }
                  }
              }
          });
  earningsContainer.addView(getRowTaxEarningsTitle());
          for (int i = 0; i &lt; taxMainObject.getTaxEarnings().size(); i++) {
  
          earningsContainer.addView(getTaxEarningsRow(taxMainObject
                      .getTaxEarnings().get(i)));
              totalEarnings += taxMainObject.getTaxEarnings().get(i)
                      .getTotalAmount();
  
          }
  
          earningsContainer.addView(getTaxTotalRow("GROSS TOTAL SALARY",
                  totalEarnings + ""));
  </code></pre>
  
  <p>Stacktrace after using ViewTreeObserver - </p>
  
  <pre><code>07-18 13:40:59.936: E/AndroidRuntime(10058): FATAL EXCEPTION: main
  07-18 13:40:59.936: E/AndroidRuntime(10058): Process: com.synthesize.paysal, PID: 10058
  07-18 13:40:59.936: E/AndroidRuntime(10058): java.lang.IllegalStateException: This ViewTreeObserver is not alive, call getViewTreeObserver() again
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.view.ViewTreeObserver.checkIsAlive(ViewTreeObserver.java:720)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.view.ViewTreeObserver.removeOnGlobalLayoutListener(ViewTreeObserver.java:529)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at com.synthesize.paysal.TaxinfoActivity$1.onGlobalLayout(TaxinfoActivity.java:125)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:815)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1782)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.view.Choreographer.doCallbacks(Choreographer.java:574)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.view.Choreographer.doFrame(Choreographer.java:544)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.os.Handler.handleCallback(Handler.java:733)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.os.Handler.dispatchMessage(Handler.java:95)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.os.Looper.loop(Looper.java:136)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at android.app.ActivityThread.main(ActivityThread.java:5017)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at java.lang.reflect.Method.invokeNative(Native Method)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at java.lang.reflect.Method.invoke(Method.java:515)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  07-18 13:40:59.936: E/AndroidRuntime(10058):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>