-3

I am trying to extends two activities inside one class. i know it is not possible, i have tried to make two different classes like this:

[Activity(Label = "DLS", Theme = "@style/MyTheme", ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]
public class ActProduct : ActionBarActivity, TabHostAct
{
        base.OnCreate(savedInstanceState);

        // Create your application here
        SetContentView(Resource.Layout.layProduct);

        mToolbar = FindViewById<SupportToolbar>(Resource.Id.toolbar);
        mDrawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
        mLeftDrawer = FindViewById<ListView>(Resource.Id.left_drawer);

        mLeftDrawer.Tag = 0;

        SetSupportActionBar(mToolbar);

        mLeftDataSet = new List<string>();
        mLeftDataSet.Add("Login");
        mLeftDataSet.Add("Camera");
        mLeftDataSet.Add("Maps");
        mLeftDataSet.Add("Product");
        mLeftAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, mLeftDataSet);
        mLeftDrawer.Adapter = mLeftAdapter;
        mLeftDrawer.ItemClick += MenuListView_ItemClick;

        mDrawerToggle = new MyActionBarDrawerToggle(
            this,                           //Host Activity
            mDrawerLayout,                  //DrawerLayout
            Resource.String.openDrawer,     //Opened Message
            Resource.String.closeDrawer     //Closed Message
        );

        mDrawerLayout.SetDrawerListener(mDrawerToggle);
        SupportActionBar.SetHomeButtonEnabled(true);
        SupportActionBar.SetDisplayShowTitleEnabled(true);
        mDrawerToggle.SyncState();
}

public class TabHostAct : TabActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        CreateTab(typeof(ActProProduk), "Prod", "Product", Resource.Drawable.ic_tab_product);
        CreateTab(typeof(ActProCustomer), "Cust", "Customer", Resource.Drawable.ic_tab_customer);
        CreateTab(typeof(ActProPromo), "Promo", "Promotion", Resource.Drawable.ic_tab_promo);
    }

    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);
    }
}

Here is my .axml layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <!-- The Main Content View -->
        <FrameLayout
            android:id="@+id/main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="25dp"
                android:layout_marginLeft="25dp">
                <TabHost
                    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>
            </LinearLayout>
        </LinearLayout>
    <!-- The Left Navigation Drawer -->
        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:divider="#818181"
            android:dividerHeight="1dp"
            android:background="#E3F2FD" />
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

is there any solution to my problem? thank you in advance.

F43nd1r
  • 7,690
  • 3
  • 24
  • 62
  • `i know it is not possible` why do you ask for a solution if you already know that there is none? – F43nd1r Apr 06 '16 at 02:23
  • i never said that i already know if there is no solution to my problem. I was just simply trying to say that it was not possible to do it with my method. I'm trying to find people who can give me a solution to my problem. – ginsawamura Apr 06 '16 at 02:27

1 Answers1

0

Do not use TabActivity. Instead, include a TabHost in your layout.

F43nd1r
  • 7,690
  • 3
  • 24
  • 62
  • I'm very sorry, i don't really get what you mean. I'm already using TabHost on my layout. TabActivity is for me to make the TabHost functionable which is run inside the class. Probably you can give me code example? – ginsawamura Apr 06 '16 at 03:42
  • http://stackoverflow.com/questions/20469877/adding-tab-inside-fragment-in-android note that AppCompatActivity also provides a Fragmentmanager. – F43nd1r Apr 06 '16 at 03:46
  • i have different activities for each drawer that i've created. Hence, creating fragment for my drawer is out of option, however i'm currently trying to make the tab layout function into fragment since i thought it uses the same activity which is "ActionBarActivity", but there is an error saying: 'ActionBar' is an ambiguous reference between 'Android.App.ActionBar' and 'Android.Support.V7.App.ActionBar' so now, i'm back to the dead end – ginsawamura Apr 06 '16 at 03:56