title: How to avoid TextView.getLayout() to return null?
body: <p>I have a TextView that the getLayout returns null.
  Which is "normal" according the documentation, because just before, I addded it to a layout, then it changes its width.</p>
  
  <p>how to avoid this?</p>
  
  <p>(i tried with a OnGlobalLayoutListener, then waiting it has its full width,  but it does not always work)</p>
  
  <p>EDIT:
  I call from an list adapter, in the getView():</p>
  
  <pre><code>drawArticle(article, true);
  </code></pre>
  
  <p>Here is the drawArticle() method:</p>
  
  <pre><code>TextView txt;
  Spanned text;
  private void drawArticle(final Article article, boolean first) {
      if(first){
          text = Html.fromHtml(article.content);
      } else {
          text = Html.fromHtml(getInvisibleText(txt));
      }
      txt = createTextView();
  
      txt.setText(text);
      layout.addView(txt);
      vto = txt.getViewTreeObserver();
      vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
              txt.getViewTreeObserver().removeGlobalOnLayoutListener(this);
              String inVisibleText = getInvisibleText(txt);
              if (inVisibleText != null &amp;&amp; !inVisibleText.isEmpty()) {
                  drawArticle(article, false);
              }
          }
      });
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>private String getInvisibleText(final TextView textView) {
      Layout staticLayout = null;
      String toDislay = "";
      int height    = textView.getHeight();
      int scrollY   = textView.getScrollY();
      staticLayout = textView.getLayout();
      int lastVisibleLineNumber  = staticLayout.getLineForVertical(scrollY+height);
      int start = staticLayout.getLineEnd(lastVisibleLineNumber);
      int end = staticLayout.getLineEnd(textView.getLineCount()-1);
      toDislay = textView.getText().toString().substring(start, end);
      return toDislay;
  }
  </code></pre>
  
  <p>This is suppose to set a very long text into a text view, then get what is not displayed to recursively put in other textviews</p>