2011-12-10 22 views
3

我在Xamarin网站上显示Tab Layout example挣扎。我已经创建了状态列表可绘制的XML文件,并将图标复制到我的可绘制目录中,但是我遇到了OnCreate方法的问题。Monodroid标签布局示例项目似乎不工作

他们列出的OnCreate方法显然被破坏,因为它缺少一个TabHost实例化。但即使修复此问题时调用

var TabHost = new TabHost(this);

我仍然得到一个空引用异常。这是直到它投行的OnCreate的完整源代码:

protected override void OnCreate(Bundle bundle) 
     { 
     base.OnCreate(bundle); 
     SetContentView(Resource.Layout.Main); 
     var TabHost = new TabHost(this); 
     TabHost.TabSpec spec;  // Resusable TabSpec for each tab 
     Intent intent;   // Reusable Intent for each tab 

     // Create an Intent to launch an Activity for the tab (to be reused) 
     intent = new Intent(this, typeof(StopWatchActivity)); 
     intent.AddFlags(ActivityFlags.NewTask); 

     // Initialize a TabSpec for each tab and add it to the TabHost 
     spec = TabHost.NewTabSpec("Stoppuhr"); 
     spec.SetIndicator("Artists", Resources.GetDrawable(Resource.Drawable.ic_tab_artists_grey)); 
     spec.SetContent(intent); 
     //Crashes with a null reference exception 
     TabHost.AddTab(spec); 
     ... 
} 

为什么TabHost.AttTab崩溃我的应用程序有一个空引用异常?作为一种替代方案,如果您可以下载一个完整的示例项目来显示与Monodroid一起使用的选项卡布局,我会很乐意将其用作参考。

回答