-1
    **An unhandled exception occurred in Tab View in Xamarin Android in VS2012**

    **This is my layout main.axml**

C# を使用して Xamarin でナレッジ タブ ビューを実装して vs2012 を使用していないので、Visual Studio のアラート ボックスで Android エミュレーターでアプリケーションを実行すると、このエラーが発生しました。

    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout
            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" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:padding="5dp" />
        </LinearLayout>
    </TabHost>

これは私の MainActiviy Activity1.cs です

    using System;

    using Android.App;
    using Android.Content;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
    using Android.OS;

    namespace TabView 
    {
        [Activity(Label = "TabView", MainLauncher = true, Icon = "@drawable/icon")]
        public class Activity1 : TabActivity
        {


            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);

                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.Main);
                CreateTab(typeof(WhatsOnActivity), "whats_on", "What's On", Resource.Drawable.ic_tab_whats_on);
                CreateTab(typeof(SpeakersActivity), "speakers", "Speakers", Resource.Drawable.ic_tab_speakers);
                CreateTab(typeof(SessionsActivity), "sessions", "Sessions", Resource.Drawable.ic_tab_sessions);
                CreateTab(typeof(MyScheduleActivity), "my_schedule", "My Schedule", Resource.Drawable.ic_tab_my_schedule);

            }
            private void CreateTab(Type activityType, string tag, string label, int drawableId)
            {
                var intent = new Intent(this, activityType);
                intent.AddFlags(ActivityFlags.NewTask);

                var spec = TabHost.NewTabSpec(tag);
                var drawableIcon = Resources.GetDrawable(drawableId);
                spec.SetIndicator(label, drawableIcon);
                spec.SetContent(intent);

                TabHost.AddTab(spec);
            }


            }
        }

アプリケーションで 4 つのタブを使用したい

    **this 1st tab activity MyScheduleActivity.cs**

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;

    namespace TabView
    {
        [Activity]
        public class MyScheduleActivity : Activity
        {
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);

                TextView textview = new TextView(this);
                textview.Text = "This is the My Schedule tab";
                SetContentView(textview);
            }
        }
    }


    **this is 2nd activity SessionsActivity.cs**

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;

    namespace TabView
    {
        [Activity]
        public class SessionsActivity : Activity
        {
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);

                TextView textview = new TextView(this);
                textview.Text = "This is the My Session tab";
                SetContentView(textview);
            }
        }
    }


    **this is 3rd activity SpeakersActivity.cs**

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;

    namespace TabView
    {
        [Activity]
        public class SpeakersActivity : Activity
        {
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);

                TextView textview = new TextView(this);
                textview.Text = "This is the My Speakers tab";
                SetContentView(textview);
            }
        }
    }

**this is 4th activity WhatsOnActivity.cs**

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace TabView
{
    [Activity]
    public class WhatsOnActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            TextView textview = new TextView(this);
            textview.Text = "This is the My Whats On tab";
            SetContentView(textview);
        }
    }
}


**AND**

**this is my xml in  Resources=>drawable folder** 

1) ic_tab_my_schedule.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/ic_tab_my_schedule" android:state_selected="true"/>
  <item android:drawable="@drawable/ic_tab_my_schedule"/>
</selector>


2)ic_tab_sessions.xml
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/ic_tab_sessions"
        android:state_selected="true"/>
  <item android:drawable="@drawable/ic_tab_sessions"/>
</selector>

3)ic_tab_speakers.xml
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/ic_tab_speakers"
        android:state_selected="true"/>
  <item android:drawable="@drawable/ic_tab_speakers"/>
</selector>

4)ic_tab_whats_on.xml
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/ic_tab_whats_on"
        android:state_selected="true"/>
  <item android:drawable="@drawable/ic_tab_whats_on"/>
</selector>

そして、ドローアブルフォルダーが選択された状態と選択されていない状態で2つの画像を追加しました!

そして私はこのリンクをたどります: -TabHostチュートリアル

事前に感謝します。あなたの反応を願っています..

4

1 に答える 1