Ejemplo n.º 1
0
        protected async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem == null)
            {
                return; //ItemSelected is called on deselection, which results in SelectedItem being set to null
            }
            string selectedCountry = e.SelectedItem.ToString();
            string url             = "http://api.population.io:80/1.0/population/" + selectedCountry + "/2016-02-01/";

            try
            {
                JsonValue jsonString = await FetchCountryPopAsync(url);

                JsonObject      jsonObject      = jsonString as JsonObject;
                TotalPopulation totalPopulation = JsonConvert.DeserializeObject <TotalPopulation>(jsonObject["total_population"].ToString());
                Country         country         = new Country();
                country.Population  = totalPopulation.Population;
                country.CountryName = e.SelectedItem.ToString();
                BdConfig.insertDB(country);
                DisplayAlert("World Population", e.SelectedItem.ToString() + " has " + totalPopulation.Population.ToString() + " people in 2016", "Cancel");
            }
            catch (Exception ex) {
                DisplayAlert("No data", "No data recorded for this year", "Cancel");
            }
        }
Ejemplo n.º 2
0
        protected override async void OnAppearing()
        {
            List <Country> countriesAsList = new List <Country>();
            string         url             = "http://api.population.io:80/1.0/countries";

            countriesAsList = BdConfig.topCountries();

            listViewCountriesTop.ItemsSource = countriesAsList;
        }
Ejemplo n.º 3
0
 public MainPage()
 {
     InitializeComponent();
     BindingContext = this;
     BdConfig.createDB();
 }