title: How to build your own tabs in MvvmCross?
body: <p>I'm trying to build my own tabs in MonoDroid and MvvmCross.</p>
  
  <p>The reason for building my own tabs is so that I can have further control over them. I want them on every screen even if they aren't in the tabs, I want to control clicks on certain tabs.</p>
  
  <p>Loading the two Fragments on the page is fine, however when I click a button that is on either the tab fragment or content fragment that navigates to the next content fragment I am getting the error message "An unhandled exception occured." which isn't so helpful.</p>
  
  <pre><code> 02-06 10:15:13.947 W/dalvikvm( 2040): JNI WARNING: JNI method called with exception pending
   02-06 10:15:13.947 W/dalvikvm( 2040):              in Lcirrious/mvvmcross/droid/fragging/MvxEventSourceFragmentActivity;.n_startActivityForResult:(Landroid/content/Intent;I)V (NewString)
   In mgmain JNI_OnLoad
   02-06 10:15:13.947 W/dalvikvm( 2040): Pending exception is:
   02-06 10:15:13.947 I/dalvikvm( 2040): android.content.ActivityNotFoundException: Unable to find explicit activity class {frags.droid/frags.droid.views.frags.ChildTwoView}; have you declared this activity in your AndroidManifest.xml?
   02-06 10:15:13.947 I/dalvikvm( 2040):   (raw stack trace not found)
   02-06 10:15:13.947 I/dalvikvm( 2040): "main" prio=5 tid=1 NATIVE
   02-06 10:15:13.947 I/dalvikvm( 2040):   | group="main" sCount=0 dsCount=0 obj=0x41aaf710 self=0x41a96210
   02-06 10:15:13.957 I/dalvikvm( 2040):   | sysTid=2040 nice=0 sched=0/0 cgrp=apps handle=1074675708
   02-06 10:15:13.957 I/dalvikvm( 2040):   | state=R schedstat=( 0 0 0 ) utm=164 stm=41 core=0
   02-06 10:15:13.967 I/dalvikvm( 2040):   #00  pc 000012fe  /system/lib/libcorkscrew.so (unwind_backtrace_thread+29)
   02-06 10:15:13.967 I/dalvikvm( 2040):   #01  pc 0006324e  /system/lib/libdvm.so (dvmDumpNativeStack(DebugOutputTarget const*, int)+33)
   02-06 10:15:13.967 I/dalvikvm( 2040):   #02  pc 000572b8  /system/lib/libdvm.so (dvmDumpThreadEx(DebugOutputTarget const*, Thread*, bool)+395)
   02-06 10:15:13.967 I/dalvikvm( 2040):   #03  pc 00057326  /system/lib/libdvm.so (dvmDumpThread(Thread*, bool)+25)
   02-06 10:15:13.967 I/dalvikvm( 2040):   #04  pc 0003b530  /system/lib/libdvm.so
   02-06 10:15:13.967 I/dalvikvm( 2040):   #05  pc 0003eef2  /system/lib/libdvm.so
   02-06 10:15:13.967 I/dalvikvm( 2040):   at cirrious.mvvmcross.droid.fragging.MvxEventSourceFragmentActivity.n_startActivityForResult(Native Method)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at cirrious.mvvmcross.droid.fragging.MvxEventSourceFragmentActivity.startActivityForResult(MvxEventSourceFragmentActivity.java:110)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at android.app.Activity.startActivity(Activity.java:3661)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at android.app.Activity.startActivity(Activity.java:3629)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at android.view.View.performClick(View.java:4475)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at android.view.View$PerformClick.run(View.java:18786)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at android.os.Handler.handleCallback(Handler.java:730)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at android.os.Handler.dispatchMessage(Handler.java:92)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at android.os.Looper.loop(Looper.java:137)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at android.app.ActivityThread.main(ActivityThread.java:5419)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at java.lang.reflect.Method.invokeNative(Native Method)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at java.lang.reflect.Method.invoke(Method.java:525)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
   02-06 10:15:13.967 I/dalvikvm( 2040):   at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>All my custom code is below.</p>
  
  <p>I have my own CustomPresenter</p>
  
  <pre><code>public class CustomPresenter : MvxAndroidViewPresenter, ICustomPresenter
  {
      // map between view-model and fragment host which creates and shows the view based on the view-model type
      private Dictionary&lt;Type, IFragmentHost&gt; dictionary = new Dictionary&lt;Type, IFragmentHost&gt;();
  
      public override void Show(MvxViewModelRequest request)
      {
          IFragmentHost host;
          if (this.dictionary.TryGetValue(request.ViewModelType, out host))
          {
              if (host.Show(request))
              {
                  return;
              }
          }
          base.Show(request);
      }
  
      public void Register(Type viewModelType, IFragmentHost host)
      {
          this.dictionary[viewModelType] = host;
      }
  }
  </code></pre>
  
  <p>I'm using a MvxFragmentActivity as my host view which will contain the content section at the top and the tabs at the bottom, this also implements IFragmentHost. All pages will be Fragments including the tabs.</p>
  
  <pre><code>public class FirstView : MvxFragmentActivity, IFragmentHost
  {
  
      ChildTwoView _childTwo;
  
      public bool Show(Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request)
      {
          // create view model
          var loaderService = Mvx.Resolve&lt;IMvxViewModelLoader&gt;();
          var viewModel = loaderService.LoadViewModel(request, null /* saved state */);
  
          _childTwo = (ChildTwoView)SupportFragmentManager.FindFragmentById(Resource.Layout.childtwoview);
  
          var customPresenter = Mvx.Resolve&lt;ICustomPresenter&gt;();
          //customPresenter.Register(Type)
  
          // decide which fragment to create based on the view-model type
  
          var fm = this.SupportFragmentManager;
          var ft = fm.BeginTransaction();
  
  
          if (viewModel.GetType().Name == "ChildTwoViewModel")
          {
              var fragmentView = new ChildTwoView();
              ft.Replace(Resource.Id.childViewHost, fragmentView);
          }
  
          //var fragmentView = viewModel.GetType().Name;
          // load fragment into view
  
  
          ft.AddToBackStack(null);
          ft.Commit();
          return true;
      }
  
      protected override void OnCreate(Bundle bundle)
      {
          base.OnCreate(bundle);
          SetContentView(Resource.Layout.FirstView);
  
          var childView = new ChildView()
          {
              ViewModel = new ChildViewModel()
          };
  
          var tabView = new TabView()
          {
              ViewModel = new TabViewModel()
          };
          var fm = this.SupportFragmentManager;
          var ft = fm.BeginTransaction();
          //ft.Add(childView, "child");
  
          ft.Replace(Resource.Id.childViewHost, childView, "child");
  
  
          ft.Replace(Resource.Id.tabViewHost, tabView, "tab");
          ft.Commit();
      }
  
  }
  </code></pre>
  
  <p>I am setting up these in the Setup.cs</p>
  
  <pre><code>protected override IMvxAndroidViewPresenter CreateViewPresenter()
  {
      var customPresenter = new CustomPresenter();
      Mvx.RegisterSingleton&lt;ICustomPresenter&gt;(customPresenter);
      return customPresenter;
  }
  </code></pre>
  
  <p>All help is greatly appreciated.</p>
  
  <p>EDIT</p>
  
  <p>I decided against this approach and went with the standard Android TabHost to keep consistency between apps.</p>