Совершенно новый для Xamarin Android. Не уверен, как именно вызвать другое представление / страницу из оператора if ниже - я видел, как другие используют для этого фрагменты или операторы case, но я только учусь, поэтому не хочу слишком сильно меняться. Это базовый шаблон навигационного ящика с VS17.
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);
}
Ниже приведено заявление if, к которому я обращался - я пытаюсь понять, как открыть другое действие или представление отсюда, когда оно выбрано.
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;
}
}