/// <summary> /// Sets the forecast information. /// </summary> private async void SetForecastInfo() { // get the weather task ready to get task for 7 das var task = new FetchWeatherTask(7); // get the location and units preferences for this data var prefs = PreferenceManager.GetDefaultSharedPreferences(Activity); var location = prefs.GetString(GetString(Resource.String.LocationPrefKey), GetString(Resource.String.LocationPrefDefault)); // get the latest weather forecast await task.ExecuteAsync(location); if (task.IsSuccessful) { var data = task.ForecastData; _listItems = data.Forecast; _forecastAdapter.Clear(); _forecastAdapter.AddAll(_listItems); } // task was not successful, let the user know else { var builder = new AlertDialog.Builder(Activity); var alert = builder.Create(); alert.SetTitle("Error: " + task.ResponseError.Code); alert.SetMessage("I'm sorry, there was an issue getting the weather: " + task.ResponseError.ErrorMessage); alert.SetButton("OK", (sender, args) => { }); alert.Show(); } }
/// <summary> /// Sets the forecast information. /// </summary> private async void SetForecastInfo() { // get the weather task ready to get task for 7 das var task = new FetchWeatherTask(7); // get the location and units preferences for this data var prefs = PreferenceManager.GetDefaultSharedPreferences(Activity); var location = prefs.GetString(GetString(Resource.String.LocationPrefKey), GetString(Resource.String.LocationPrefDefault)); // get the latest weather forecast await task.ExecuteAsync(location); if (task.IsSuccessful) { var data = task.ForecastData; _listItems = data.Forecast; _forecastAdapter.Clear(); _forecastAdapter.AddAll(_listItems); } // task was not successful, let the user know else { var builder = new AlertDialog.Builder(Activity); var alert = builder.Create(); alert.SetTitle("Error: " + task.ResponseError.Code); alert.SetMessage("I'm sorry, there was an issue getting the weather: " + task.ResponseError.ErrorMessage); alert.SetButton("OK", (sender, args) => { }); alert.Show(); } }