void ListItemClicked(int itemId) { //this way we don't load twice, but you might want to modify this a bit. if (itemId == oldPosition) { return; } shouldClose = false; oldPosition = itemId; Android.Support.V4.App.Fragment fragment = null; switch (itemId) { case Resource.Id.menu_past_trips: //7fragment = FragmentPastTrips.NewInstance(); break; case Resource.Id.menu_current_trip: fragment = FragmentCurrentTrip.NewInstance(); break; case Resource.Id.menu_profile: //8fragment = FragmentProfile.NewInstance(); break; case Resource.Id.menu_settings: //9fragment = FragmentSettings.NewInstance(); break; } if (fragment != null) { SupportFragmentManager.BeginTransaction() .Replace(Resource.Id.content_frame, fragment) .Commit(); } //10 navigationView.SetCheckedItem(itemId); }
protected async override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); #if !XTC //2 InitializeHockeyApp(); #endif drawerLayout = FindViewById <DrawerLayout>(Resource.Id.drawer_layout); //Set hamburger items menu SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu); //setup navigation view /*3 navigationView = FindViewById<NavigationView>(Resource.Id.nav_view); * * //handle navigation * navigationView.NavigationItemSelected += (sender, e) => * { * e.MenuItem.SetChecked(true); * * ListItemClicked(e.MenuItem.ItemId); * * * SupportActionBar.Title = e.MenuItem.ItemId == Resource.Id.menu_profile * ? Settings.Current.UserFirstName * : e.MenuItem.TitleFormatted.ToString(); * * SupportActionBar.Title = e.MenuItem.TitleFormatted.ToString(); * * drawerLayout.CloseDrawers(); * }; */ if (Intent.GetBooleanExtra("tracking", false)) { ListItemClicked(Resource.Id.menu_current_trip); SupportActionBar.Title = "Current Trip"; return; } global::Xamarin.Forms.Forms.Init(this, bundle); Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle); SetContentView(LayoutResource); await MyDriving.Services.OBDDataProcessor.GetProcessor().Initialize(ViewModel.ViewModelBase.StoreManager); //await MyDriving.Services.OBDDataProcessor.GetProcessor().Initialize(); Android.Support.V4.App.Fragment fragment = null; fragment = FragmentCurrentTrip.NewInstance(); SupportFragmentManager.BeginTransaction() .Replace(Resource.Id.content_frame, fragment) .Commit(); //if first time you will want to go ahead and click first item. /*4 * if (bundle == null) * { * ListItemClicked(Resource.Id.menu_current_trip); * SupportActionBar.Title = "Current Trip"; * }*/ }