0

私はこの問題が似たようなので、thisと言いました。Android用のモノラルでタブコントロールを操作する

私の主な活動では、私はクラスTabControlActivityGroupに広げています。

は私がActivityGroupにできなくなりますCustom_Title機能を使用したいと私はActivityGroupから私のメインクラスを拡張することはできませんのでご注意ください。

1)。メインクラス:

public class MainActivity: Activity 
{ 
    TabControl _tabControl; 
    protected override void OnCreate (Bundle bundle) 
    { 
     _tabControl=new TabControl(); 
    _tabControl.CreateTabs(); 
    } 
} 

2)のTabControlクラス:

public class TabControl:ActivityGroup 
    { 
     TabHost tabHost; 

     protected override void OnCreate (Bundle bundle) 
     {    
      base.OnCreate (bundle); 
      SetContentView(Resource.Layout.TabView); 
     } 

    public void CreateTabs() 
    { 
     try 
     { 
      tabHost=(TabHost)FindViewById(Resource.Id.tabHost); 
     LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false); 
      tabHost.Setup(mLocalActivityManager); 
      //tabHost.Setup();    

     TabHost.TabSpec spec; 
     Intent intent; 

     intent = new Intent (this, typeof (MainActivity)); 
     intent.AddFlags (ActivityFlags.NewTask); 

       spec=tabHost.NewTabSpec("Heat Map"); 
       spec.SetIndicator("Heat Map"); 
       spec.SetContent(intent); 
       tabHost.AddTab(spec); 

     intent = new Intent (this, typeof (LiveMkt)); 
     intent.AddFlags (ActivityFlags.NewTask); 

       spec=tabHost.NewTabSpec("Live Mkt"); 
       spec.SetIndicator("Live Mkt"); 
       spec.SetContent(intent); 
       tabHost.AddTab(spec); 

       tabHost.CurrentTab = 1;     
      } 
      catch(Exception ex) 
      {} 
     }  
    } 

3)TabView.xml:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/tabLayout"> 

<TabHost 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/tabHost" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
     <RelativeLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5dp"> 
      <TabWidget 
        android:id="@android:id/tabs" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"    
        android:layout_alignParentBottom="true" /> 
      <FrameLayout 
        android:id="@android:id/tabcontent" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:padding="5dp"  
        android:layout_alignParentTop="true"/> 
     </RelativeLayout> 
</TabHost> 
</RelativeLayout> 

しかし、私は次のエラーを取得しています:

Module Name : TabControl 

Method Name : CreateTabs 

Exception Details : Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown. 

at Android.Runtime.JNIEnv.CallNonvirtualObjectMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in <filename unknown>:0 

at Android.App.Activity.FindViewById (Int32 id) [0x00000] in <filename unknown>:0 

at StockGadget.Controls.TabControl.CreateTabs() [0x00000] in <filename unknown>:0 

--- End of managed exception stack trace --- 

java.lang.NullPointerException 

at android.app.Activity.findViewById(Activity.java:1637) 

私は絶対Mono for Androidに初心者、任意のヘルプ感謝...あなたの主な活動で

答えて

0

、ちょうどタブコントロールを作成し、それを介して他のすべてのアクティビティを参照してくださいよと。 メインアクティビティをTabActivityから拡張します。

関連する問題