title: How to get the content of a Tab within a TabHost?
body: <p>I have an Activity defined by:</p>
  
  <pre><code>&lt;LinearLayout
          android:id="@+id/TabContainer"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="99"
          android:orientation="vertical"&gt;
    &lt;TabHost
          android:id="@+android:id/tabhost"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
      &lt;LinearLayout
          android:id="@+id/TabLinearLayout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"&gt;
        &lt;TabWidget
          android:id="@+android:id/tabs"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;&lt;/TabWidget&gt;
        &lt;FrameLayout
          android:id="@+android:id/tabcontent"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_marginTop="10dp"&gt;&lt;/FrameLayout&gt;
      &lt;/LinearLayout&gt;
    &lt;/TabHost&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Basically it's a TabHost with TextViews as contents. I'm building the tabs and the content of those TextViews dynamically with createTabContent(). That works fine. But under some circumstances (some events processed by an AsyncTask with a TCP socket), I need to change the content of the some of those TextViews.</p>
  
  <p>I'm convinced my problem is the result of my inexperience with Android SDK, but I can't find a way to iterate over the TabHost and get the content for each of those TextViews.</p>
  
  <p>The "closest" approach I have achieved is:</p>
  
  <pre><code>TabHost th = (TabHost) findViewById(android.R.id.tabhost);
  TabWidget tw = th.getTabWidget();    
  
  for (int i = 0; i &lt; tw.getChildCount(); i++) {
    LinearLayout lLayout = (LinearLayout) tw.getChildAt(i);
    TextView tv = ((TextView) lLayout.getChildAt(i));      
  
    tv.append(linea);
  }
  </code></pre>
  
  <p>But what this does is to append that "linea" to the <strong>name</strong> of the tab (to the Indicator). I want to add it to the <strong>content</strong> of that tab, but I can't find a way to retrieve the TextView associated to it.</p>
  
  <p>Any ideas will be very appreciated!</p>
  
  <p><strong>--------- EDIT ---------</strong></p>
  
  <p>Although in a comment below I posted that I already had a solution, I found out it's not valid. The code looks now like this:</p>
  
  <pre><code>for (int i = 0; i &lt; tw.getChildCount(); i++) {
    LinearLayout LLayout = (LinearLayout) tw.getChildAt(i);
    TextView currenttab = (TextView) LLayout.getChildAt(0);
  
    if (tab.equals(currenttab.getText())) {
      th.setCurrentTab(i);
      TextView tabContent = (TextView) th.getTabContentView().getChildAt(0);
      tabContent.append(linea);
      return true;
    }
  }
  </code></pre>
  
  <p>The problem is that getTabContentView() references only to the active Tab at that moment, so if I want to add some text to a non-selected tab's TextView, I have to select it previously with .setCurrentTab(i), what means that I'd be changing the active Tab...</p>
  
  <p>I think this has to be a lot easier than I'm thinking about... Any help with this?</p>
  
  <p>Thanks!</p>
  
  <p><strong>--------- EDIT ---------</strong></p>
  
  <p>At that point I've realized that accessing an inactive tab's contents is not possible. At least not that way. Supposedly you cannot access an inactive tab's view because it has not an associated view, at least not a public one.</p>
  
  <p>I've tried to declare a Map, where the first String is the tab's name, and the second is the TextView associated to its contents, and assign them in the moment of the tab creation. The result was that I was only able to reference the TextView of the active tab, the other ones threw a NullPointer exception.</p>
  
  <p>So I focused the problem differently. Now if I have to add some text into an inactive tab, I add that text to a Hash, I declared an OnTabChangeListener and each time I change a tab I dump the pending content into it.</p>
  
  <p>It's not the most brilliant solution, but it's the only one I got working... so if someone has a better solution to this I'll be grateful.</p>