title: android: a tab host where each tab has an unread count badge
body: <p>I need to write a tab bar where each of the tabspecs has an indicator view that contains a changable numeric badge.
  imagine a tabbed news reader where each tab has it's own unread count</p>
  
  <p>What I did is create an xml layout for the tab inidicator, inflated it in code and associated it with the tabspec like so:
  tab_indicator.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content" android:layout_height="wrap_content"
      android:orientation="vertical" android:paddingLeft="10dip"
      android:paddingRight="10dip"&gt;
      &lt;FrameLayout android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:paddingTop="5dip"&gt;
  
          &lt;ImageView android:src="@drawable/tab_selector_friends"
              android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt;
          &lt;TextView android:text="2" 
              android:layout_width="10dip" android:layout_height="10dip" 
              android:textColor="@color/white_text"
              android:textStyle="bold" android:typeface="monospace"
              android:paddingLeft="1dip" android:paddingRight="1dip"
              android:textSize="10dip" android:gravity="center" android:background="@drawable/temp_red_badge_big" /&gt;
  
      &lt;/FrameLayout&gt;
      &lt;TextView android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:text="Friends" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>my tab widget (oncreate metod of MyTabWidget.java):</p>
  
  <pre><code>    @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.tab_menu);
  
      TabHost tabHost = getTabHost();
      Intent intent = new Intent().setClass(this, TodayActivity.class);
      Resources resources = this.getResources();  
      TabHost.TabSpec spec = tabHost.newTabSpec(resources.getString(R.string.today));
      View specIndicatorView;
      LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      specIndicatorView = inflater.inflate(R.layout.tab_indicator, null);
      spec.setIndicator(specIndicatorView);
      spec.setContent(intent);
      tabHost.addTab(spec);
  </code></pre>
  
  <p>There are several issues with this approach:</p>
  
  <ol>
  <li>It is extremely convoluted and hard to maintain</li>
  <li>It does not afford me the flexibility I require, i.e. change the value of the badge</li>
  <li>It is very hard to design it in a way that looks good</li>
  <li>It just seems like it's too complicated an approach</li>
  </ol>
  
  <p>My question is, can you suggest a better way to do this? is there a different approach I didn't consider?
  Thanks!</p>