Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

TabHost in fragment

$
0
0

Hello i am trying to add a tabhost to a fragment. but i am betting an error when i debug the app
Android.Content.ActivityNotFoundException: Unable to find explicit activity class {App1.App1/md5579855c995bdb073d8182511e793544c.FragmentB}; have you declared this activity in your AndroidManifest.xml?

main.cs

namespace App1
{
    [Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : FragmentActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            Android.App.FragmentTransaction fragmentTx = this.FragmentManager.BeginTransaction();
            Android.App.Fragment fa = new FragmentA();

            fragmentTx.Add(Resource.Id.fragment_container, fa);

            fragmentTx.Commit();
        }
    }
}

FragmentA.axml note: i removed all the < and no links allowed

?xml version="1.0" encoding="utf-8"?>
LinearLayout xmlns:android=""
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minWidth="25px"
    android:minHeight="25px">
    TabHost
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:minWidth="25px"
        android:minHeight="25px"
        android:id="@+id/tabHost1">
        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
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/linearLayout2" />
                LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/linearLayout3" />
                LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/linearLayout4" />
            /FrameLayout>
        /LinearLayout>
    /TabHost>
/LinearLayout>

Fragment.cs

namespace App1
{
    public class FragmentA : Fragment
    {
        private TabHost mTabHost;

        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your fragment here
        }

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View rootView = inflater.Inflate(Resource.Layout.FragmentA, container, false);
            mTabHost = rootView.FindViewById<TabHost>(Resource.Id.tabHost1);
            LocalActivityManager mLocalActivityManager = new LocalActivityManager(this.Activity , false);
            mLocalActivityManager.DispatchCreate(savedInstanceState);
            mTabHost.Setup(mLocalActivityManager);

            TabHost.TabSpec spec = mTabHost.NewTabSpec("Tab One");
            var intent = new Intent(this.Activity, typeof(FragmentB));
            intent.AddFlags(ActivityFlags.NewTask);
            spec.SetContent(intent);
            spec.SetIndicator("Tab One");
            mTabHost.AddTab(spec); //<---------------------------------------------------------------- The error ocures here

            TabHost.TabSpec spec2 = mTabHost.NewTabSpec("Tab Two");
            var intent2 = new Intent(this.Activity, typeof(FragmentC));
            intent2.AddFlags(ActivityFlags.NewTask);
            spec2.SetContent(intent2);
            spec2.SetIndicator("Tab Two");
            mTabHost.AddTab(spec2);

            return rootView;
        }
    }
}

so my question is why am i getting this error and is this even possible?


Viewing all articles
Browse latest Browse all 204402

Trending Articles