2016-08-03 7 views
0

私はしばらくの間、私のプロジェクトに一対のタブを実装しようとしてきました。私はそれを行う方法についてかなり読んできましたが、なぜそれが機能していないのか分かりません。誰かが私に間違っていることを教えてもらえますか?ここに私は.csAndroidタブが正しく動作しないC#

public class TabActivity1 : Activity 
{ 
    protected override void OnCreate(Bundle savedInstanceState) 
    { 
     base.OnCreate(savedInstanceState); 
     TextView textview = new TextView(this); 
     textview.Text = "Tab 1"; 
     SetContentView(textview); 
    } 
} 

public class TabActivity2 : Activity 
{ 
    protected override void OnCreate(Bundle savedInstanceState) 
    { 
     base.OnCreate(savedInstanceState); 
     TextView textview = new TextView(this); 
     textview.Text = "Tab 2"; 
     SetContentView(textview); 
    } 
} 


public class MainActivity : Activity 
{ 
    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 
     SetContentView(Resource.Layout.Main); 

     TabHost tab_host = FindViewById<TabHost>(Resource.Id.tabHost); 
     TabHost.TabSpec spec; 
     Intent intent; 

     intent = new Intent(this, typeof(TabActivity1)); 
     intent.AddFlags(ActivityFlags.NewTask); 
     spec = tab_host.NewTabSpec("Tab 1"); 
     spec.SetIndicator("tab1"); 
     spec.SetContent(intent); 
     tab_host.AddTab(spec); 

     intent = new Intent(this, typeof(TabActivity2)); 
     intent.AddFlags(ActivityFlags.NewTask); 
     spec = tab_host.NewTabSpec("Tab 2"); 
     spec.SetIndicator("tab2"); 
     spec.SetContent(intent); 
     tab_host.AddTab(spec); 
    } 
} 

だここで何のアプリ出力.axml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:minWidth="25px" 
android:minHeight="25px"> 
<TabHost 
    android:minWidth="25px" 
    android:minHeight="25px" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/tabHost"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:id="@+id/linearLayout1"> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 
</TabHost> 
</LinearLayout> 

Here年代です。

本当にありがとうございました。ありがとうございます。

+0

期待される出力は何ですか?コードを見るだけで、望みの結果を推測するのはかなり面倒です。 – hankide

+0

タブ1とタブ2というラベルのついた2つのタブがあり、それぞれのタブにタブ1のタブ1とタブ2のタブ2というテキストボックスがあることを期待していました。これを達成するために何ができると思いますか? –

答えて

0

私はいくつかの調査をした結果、Activity TabActivityが推奨されなくなったことを知ったので、ページスライダやスライディングタブなどのタブを実装する別の方法を見つけなければなりません。

関連する問題