/// <summary> /// This method refreshes the fragment once the data is retrieved from web service /// </summary> public void RefreshFragment() { Fragment currentFragment =null; try { currentFragment = new CurrentFragment(true); if (currentFragment != null) { FragmentTransaction transaction = FragmentManager.BeginTransaction(); transaction.Replace(Resource.Id.fragment_container, currentFragment); transaction.Commit(); } } catch (Exception ex) { Toast.MakeText(this, GlobalConstants.ErrorMessage + ex.ToString(), ToastLength.Short); } }
/// <summary> /// Method to create tabs using action bar /// </summary> private void setTabs() { try { ActionBar actionBar = this.ActionBar; actionBar.NavigationMode = ActionBarNavigationMode.Tabs; ActionBar.Tab tabCurrentWeather = ActionBar.NewTab(); tabCurrentWeather.SetText("Current Weather"); tabCurrentWeather.TabSelected += (sender, args) => { Fragment currentFragment = null; if (IsResponseRecieved) { currentFragment = new CurrentFragment(true); } else { currentFragment = new CurrentFragment(false); } if (currentFragment != null) { FragmentTransaction transaction = FragmentManager.BeginTransaction(); transaction.Replace(Resource.Id.fragment_container, currentFragment); transaction.Commit(); } }; ActionBar.AddTab(tabCurrentWeather); ActionBar.Tab tabHourlyWeather = ActionBar.NewTab(); tabHourlyWeather.SetText("Hourly Weather"); tabHourlyWeather.TabSelected += (sender, args) => { Fragment hourlyFragment = new HourlyFragment(); if (hourlyFragment != null) { FragmentTransaction transaction = FragmentManager.BeginTransaction(); transaction.Replace(Resource.Id.fragment_container, hourlyFragment); transaction.Commit(); } }; ActionBar.AddTab(tabHourlyWeather); ActionBar.Tab tabDailyWeather = ActionBar.NewTab(); tabDailyWeather.SetText("Daily Weather"); tabDailyWeather.TabSelected += (sender, args) => { Fragment dailyFragment = new DailyFragment(); FragmentTransaction transaction = FragmentManager.BeginTransaction(); transaction.Replace(Resource.Id.fragment_container, dailyFragment); transaction.Commit(); }; ActionBar.AddTab(tabDailyWeather); } catch( Exception ex) { Toast.MakeText(this, GlobalConstants.ErrorMessage + ex.ToString(), ToastLength.Short); } }