Opening another Page from Menu

DevvDevv USMember ✭✭

Hi folks - I'm taking leap into Xamarin Android and recently started using the Navigation Drawer Template with VS17. I'm not quite sure how I call another form from the menu as shown below;

``` protected override void OnCreate(Bundle savedInstanceState)
{

        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.activity_main);
        Android.Support.V7.Widget.Toolbar toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
        SetSupportActionBar(toolbar);

        FloatingActionButton fab = FindViewById<FloatingActionButton>(Resource.Id.fab);
        fab.Click += FabOnClick;

        DrawerLayout drawer = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close);
        drawer.AddDrawerListener(toggle);
        toggle.SyncState();

        NavigationView navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
        navigationView.SetNavigationItemSelectedListener(this);
    }

    public override void OnBackPressed()
    {
        DrawerLayout drawer = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
        if(drawer.IsDrawerOpen(GravityCompat.Start))
        {
            drawer.CloseDrawer(GravityCompat.Start);
        }
        else
        {
            base.OnBackPressed();
        }
    }

    public override bool OnCreateOptionsMenu(IMenu menu)
    {
        MenuInflater.Inflate(Resource.Menu.menu_main, menu);
        return true;
    }

    public override bool OnOptionsItemSelected(IMenuItem item)
    {
        int id = item.ItemId;
        if (id == Resource.Id.action_settings)
        {
            return true;
        }

        return base.OnOptionsItemSelected(item);
    }

    private void FabOnClick(object sender, EventArgs eventArgs)
    {
        View view = (View) sender;
        Snackbar.Make(view, "Please send feedback.", Snackbar.LengthLong)
            .SetAction("Action", (Android.Views.View.IOnClickListener)null).Show();
    }


    public bool OnNavigationItemSelected(IMenuItem item)
    {

        int id = item.ItemId;

        if (id == Resource.Id.nav_support)
        {

        }

        else if (id == Resource.Id.nav_housing)
        {

        }
        else if (id == Resource.Id.nav_council)
        {

        }
        else if (id == Resource.Id.nav_education)
        {

        }
        else if (id == Resource.Id.nav_employment)
        {

        }
        else if (id == Resource.Id.nav_transport)
        {

        }
        else if (id == Resource.Id.nav_policing)
        {


        }
        else if (id == Resource.Id.nav_fire)
        {

        }
        else if (id == Resource.Id.nav_medical)
        {

        }
        DrawerLayout drawer = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
        drawer.CloseDrawer(GravityCompat.Start);
        return true;
    }
}

}
```

Do I call the form from the IF statement listed above? - I've seen and used a case statement in this instance, but with this default template they used a large if.else statement.

Any guidance would be fantastic.

Sign In or Register to comment.