title: Adding tabs dynamically in tabhost from database
body: <p>I try to add tabs in tabhost dynamically from data which I extract from database. But usually I get exceptions. I want to use this tabhost in activity.</p>
  
  <p>This is my code : </p>
  
  <h1>Main.cs</h1>
  
  <pre><code>[Activity (Label = "Main",Theme = "@style/Theme.Splash")]
  public class Main : Activity
  {
          TabHost tabHost;
  
      protected override void OnCreate (Bundle bundle)
      {
          base.OnCreate (bundle);
  
          SetContentView (Resource.Layout.activity_main);
          tabHost = FindViewById&lt;TabHost&gt;(Resource.Id.tabHost1);
  
          LocalActivityManager localActMgr = new LocalActivityManager(this, false);
          localActMgr.DispatchCreate(bundle);
  
          CSList&lt;CategoriesArticlesConfig&gt; categories = CategoriesArticlesConfig.List();
  
          tabHost.Setup(localActMgr);
  
          foreach (CategoriesArticlesConfig categorie in categories)
          {
              Intent i = new Intent();
              i.SetFlags(ActivityFlags.NewTask);
              i.PutExtra("CategorieID", categorie.CategorieArticlesConfigID);
              i.SetClass(this, typeof(AfficheArticlesTab));
              TabHost.TabSpec tab = tabHost.NewTabSpec("tab_"+categorie.CategorieArticlesConfigID);
              tab.SetIndicator(""+categorie.Nom, Resources.GetDrawable(Android.Resource.Drawable.IcInputAdd));
              tab.SetContent(i);
              tabHost.AddTab(tab);
          }            
      }
  }
  </code></pre>
  
  <h1>AfficheArticlesTab.cs</h1>
  
  <pre><code>class AfficheArticlesTab : Activity
  {
      public AfficheArticlesTab() { }
  
      protected override void OnCreate(Bundle bundle)
      {
          base.OnCreate(bundle);
          SetContentView(Resource.Layout.activity_configuration);
  
          GridView gridView = FindViewById&lt;GridView&gt;(Resource.Id.gv_item_articles_gridview_articles_tab_main_activity);
          LayoutInflater layoutInflater = (LayoutInflater)GetSystemService(Context.LayoutInflaterService);
          View view = layoutInflater.Inflate(Resource.Layout.gridview_articles_tab, null);
  
          int CategorieID = Intent.Extras.GetInt("CategorieID");
  
          CategoriesArticlesConfig categorie = CategoriesArticlesConfig.ReadFirst("CategorieArticlesID="+CategorieID);
          gridView.Adapter = new ListArticleConfigAdapter(this,categorie.ArticlesConfig.ToList&lt;ArticlesConfig&gt;());
      }
  }
  </code></pre>
  
  <h1>activity_main.axml</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:minWidth="25px"
  android:minHeight="25px"
  android:background="@drawable/background_simple"
  android:padding="5dp"&gt;
  &lt;FrameLayout
      android:minWidth="25px"
      android:minHeight="25px"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/frameLayout1"
      android:layout_margin="5dp"
      android:layout_weight="0.5"&gt;
      &lt;LinearLayout
          android:orientation="vertical"
          android:minWidth="25px"
          android:minHeight="25px"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:id="@+id/linearLayout11"&gt;
          &lt;LinearLayout
              android:orientation="horizontal"
              android:minWidth="25px"
              android:minHeight="25px"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:id="@+id/linearLayout12"
              android:layout_weight="4"&gt;
              &lt;LinearLayout
                  android:orientation="vertical"
                  android:minWidth="25px"
                  android:minHeight="25px"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:id="@+id/linearLayout13"
                  android:layout_marginTop="14.0dp"
                  android:layout_marginLeft="8.0dp"&gt;
                  &lt;LinearLayout
                      android:orientation="horizontal"
                      android:minWidth="25px"
                      android:minHeight="25px"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:id="@+id/linearLayout18"&gt;
                      &lt;TextView
                          android:textAppearance="?android:attr/textAppearanceMedium"
                          android:layout_width="wrap_content"
                          android:layout_height="fill_parent"
                          android:id="@+id/tv_num_ticket_activity_main" /&gt;
                      &lt;TextView
                          android:textAppearance="?android:attr/textAppearanceMedium"
                          android:layout_width="wrap_content"
                          android:layout_height="fill_parent"
                          android:id="@+id/tv_num_caissier_activity_main"
                          android:layout_marginLeft="10dp" /&gt;
                  &lt;/LinearLayout&gt;
                  &lt;LinearLayout
                      android:orientation="horizontal"
                      android:minWidth="25px"
                      android:minHeight="25px"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:id="@+id/linearLayout14"&gt;
                      &lt;LinearLayout
                          android:orientation="horizontal"
                          android:minWidth="25px"
                          android:minHeight="25px"
                          android:layout_width="fill_parent"
                          android:layout_height="fill_parent"
                          android:id="@+id/linearLayout15"
                          android:layout_weight="0.1"&gt;
                          &lt;EditText
                              android:inputType="numberDecimal"
                              android:layout_width="fill_parent"
                              android:layout_height="wrap_content"
                              android:id="@+id/ed_zone_main_activity"
                              android:layout_weight="0.16"
                              android:layout_marginTop="0.0dp" /&gt;
                          &lt;TextView
                              android:text="@string/qte_value"
                              android:textAppearance="?android:attr/textAppearanceMedium"
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:id="@+id/tv_qte_value_main_activity"
                              android:layout_weight="0.3"
                              android:layout_marginRight="2.5dp"
                              android:layout_marginLeft="13.3dp"
                              android:layout_gravity="center_vertical"
                              android:gravity="right"
                              android:layout_marginTop="0.0dp"
                              android:textSize="20sp" /&gt;
                      &lt;/LinearLayout&gt;
                  &lt;/LinearLayout&gt;
              &lt;/LinearLayout&gt;
          &lt;/LinearLayout&gt;
          &lt;ListView
              android:minWidth="25px"
              android:minHeight="25px"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:id="@+id/listView1"
              android:layout_weight="1"
              android:layout_marginTop="8.0dp" /&gt;
      &lt;/LinearLayout&gt;
  &lt;/FrameLayout&gt;
  &lt;LinearLayout
      android:orientation="vertical"
      android:minWidth="25px"
      android:minHeight="25px"
      android:layout_width="match_parent"
      android:layout_height="fill_parent"
      android:id="@+id/linearLayout17"
      android:layout_weight="0.3"&gt;
      &lt;FrameLayout
          android:minWidth="25px"
          android:minHeight="25px"
          android:id="@+id/frameLayout2"
          android:layout_width="fill_parent"
          android:layout_height="match_parent"
          android:layout_weight="0.15"&gt;
          &lt;LinearLayout
              android:orientation="vertical"
              android:minWidth="25px"
              android:minHeight="25px"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:id="@+id/linearLayout5"&gt;
              &lt;TabHost
                  android:minWidth="25px"
                  android:minHeight="25px"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/tabHost1"&gt;
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:orientation="vertical"
                      android:id="@+id/linearLayout19"&gt;
                      &lt;TabWidget
                          android:id="@android:id/tabs"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content" /&gt;
                      &lt;FrameLayout
                          android:id="@android:id/tabcontent"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent" /&gt;
                  &lt;/LinearLayout&gt;
              &lt;/TabHost&gt;
          &lt;/LinearLayout&gt;
      &lt;/FrameLayout&gt;
      &lt;LinearLayout
          android:orientation="horizontal"
          android:minWidth="25px"
          android:minHeight="25px"
          android:id="@+id/linearLayout16"
          android:layout_width="fill_parent"
          android:layout_height="match_parent"
          android:layout_weight="0.85"&gt;
          &lt;Button
              android:text="@string/total"
              android:id="@+id/bt_total_activity_main"
              android:textSize="16sp"
              android:layout_width="match_parent"
              android:layout_height="fill_parent"
              android:layout_weight="1"
              android:background="@drawable/button_selector_rouge" /&gt;
          &lt;Button
              android:text="@string/quantitee"
              android:id="@+id/bt_quantitee_activity_main"
              android:textSize="16sp"
              android:layout_width="match_parent"
              android:layout_height="fill_parent"
              android:layout_weight="1"
              android:background="@drawable/button_selector_enter" /&gt;
          &lt;Button
              android:text="@string/code_barre"
              android:layout_width="match_parent"
              android:layout_height="fill_parent"
              android:id="@+id/bt_code_barre_activity_main"
              android:layout_weight="1"
              android:textSize="16sp"
              android:background="@drawable/button_selector_enter" /&gt;
          &lt;Button
              android:text="@string/annuler"
              android:layout_width="match_parent"
              android:layout_height="fill_parent"
              android:id="@+id/bt_annuler_activity_main"
              android:layout_weight="1"
              android:textSize="16sp"
              android:background="@drawable/button_selector_enter" /&gt;
          &lt;Button
              android:text="@string/remise"
              android:layout_width="match_parent"
              android:layout_height="fill_parent"
              android:id="@+id/bt_remise_activity_main"
              android:layout_weight="1"
              android:textSize="16sp"
              android:background="@drawable/button_selector_enter" /&gt;
          &lt;Button
              android:text="@string/attente"
              android:layout_width="match_parent"
              android:layout_height="fill_parent"
              android:id="@+id/bt_attente_activity_main"
              android:layout_weight="1"
              android:textSize="16sp"
              android:background="@drawable/button_selector_enter" /&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>03-03 13:19:08.004 E/mono    ( 7331): Unhandled Exception:
  03-03 13:19:08.004 E/mono    ( 7331): Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown.
  03-03 13:19:08.004 E/mono    ( 7331): at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr,Android.Runtime.JValue[]) [0x00023] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:368
  03-03 13:19:08.004 E/mono    ( 7331): at Android.Widget.TabHost.AddTab (Android.Widget.TabHost/TabSpec) [0x0003e] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/platforms/android-14/src/generated/Android.Widget.TabHost.cs:762
  03-03 13:19:08.004 E/mono    ( 7331): at SymaMobile.Droid.Main.OnCreate (Android.OS.Bundle) [0x000e8] in f:\PFE\VS2012\SymaMobile\SymaMobile\SymaMobile.Droid\Activities\Main.cs:41
  03-03 13:19:08.004 E/mono    ( 7331): at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/platforms/android-14/src/generated/Android.App.Activity.cs:1859
  03-03 13:19:08.004 E/mono    ( 7331): at (wrapper dynamic-m
  </code></pre>