protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            _favoriteService = new FavoriteService();

            SetContentView(Resource.Layout.Favorites);

            var         jokesList = FindViewById <ListView>(Resource.Id.jokesListView);
            JokeAdapter adapter   = new JokeAdapter(this, _favoriteService.GetAll().ToArray());

            jokesList.Adapter    = adapter;
            jokesList.ItemClick += FavoriteClicked;
        }
예제 #2
0
        /// <summary>
        /// Update the joke list fetching data from the service
        /// </summary>
        public void DownloadJokesAndUpdateListView()
        {
            // Get the JSON from the service
            var wc           = new WebClient();
            var jsonResponse = wc.DownloadString("http://randomjoke.azurewebsites.net/api/jokes");

            wc.Dispose();

            // Deserialize the JSON response to C# objects
            ApiResponse response = JsonConvert.DeserializeObject <ApiResponse>(jsonResponse);

            // Create the adapter with new jokes and affect it to the ListView
            JokeAdapter adapter = new JokeAdapter(this, response.value);

            _jokesListView.Adapter = adapter;

            // Ensure the visual list is updated by notifying the interface
            adapter.NotifyDataSetChanged();
        }