protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.rest_save_layout); //инициализация btn_main = FindViewById <Button>(Resource.Id.btn_goto_main); list = FindViewById <ListView>(Resource.Id.listView_text); restaurant_collection = JsonConvert.DeserializeObject <RestaurantsResponce>(Intent.GetStringExtra("restaurants")); city_id = Intent.GetStringExtra("city_id" ?? "Not recv"); list.ItemClick += new EventHandler <AdapterView.ItemClickEventArgs>(GetIndex); Run(); //к фильтрам btn_main.Click += delegate { Intent nextActivity = new Intent(this, typeof(FiltersActivity)); nextActivity.PutExtra("city_id", city_id); StartActivity(nextActivity); }; }
//метод для обращения к API async void GetListAsync() { string path = BasePath + "/search?entity_id=" + city_id + "&entity_type=city&count=" + count.ToString(); if (cuisine_id != "-1") { path += $"&cuisines={cuisine_id}"; } if (collection_id != "-1") { path += $"$collection_id={collection_id}"; } if (category_id != "-1") { path += $"$category_id={category_id}"; } if (sort != "-1") { path += $"&sort={sort}"; path += $"&order={sort_dir}"; } try { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("user-key", apiKey); Android.Support.V7.App.AlertDialog dialog = new EDMTDialogBuilder().SetContext(this).SetMessage("Please wait..").Build(); if (!dialog.IsShowing) { dialog.Show(); } HttpResponseMessage response = null; try { response = await client.GetAsync(path); } catch (HttpRequestException) { Toast.MakeText(this, text: "Отсутсвует подключение к интернету!", duration: ToastLength.Long).Show(); return; } restaurant_collection = JsonConvert.DeserializeObject <RestaurantsResponce>(await response.Content.ReadAsStringAsync()); restaurants = restaurant_collection.restaurants; foreach (var restaurant in restaurants) { restaurants_names.Add(restaurant.restaurant.name); } var adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1, restaurants_names); list_restaurants.Adapter = adapter; if (dialog.IsShowing) { dialog.Dismiss(); } } catch (Exception ex) { Toast.MakeText(this, "" + ex.Message, ToastLength.Long).Show(); } }