ListView in Xamarin using RestApi ListView in Xamarin using RestApi json json

ListView in Xamarin using RestApi


First need to create a local model class :

public class TodoItem{    public string id { get; set; }    public string employee_name { get; set; }    public string employee_salary{ get; set; }    public bool employee_age { get; set; }    public bool profile_image { get; set; }}

And in the RestService can use TodoItem:

public List<TodoItem> Items { get; private set; }public async Task<List<TodoItem>> RefreshDataAsync (){   Items = new List<TodoItem> (); // RestUrl = http://developer.xamarin.com:8081/api/todoitems   var uri = new Uri (string.Format (Constants.RestUrl, string.Empty));   try {       var response = await client.GetAsync (uri);       if (response.IsSuccessStatusCode) {           var content = await response.Content.ReadAsStringAsync ();           Items = JsonConvert.DeserializeObject <List<TodoItem>> (content);        }    } catch (Exception ex) {           Debug.WriteLine (@"ERROR {0}", ex.Message);    }    return Items;}

And last where your listview itemsource can set as follow:

listView.ItemsSource = await RestService.RefreshDataAsync();

Note: Here is a official sample you can refer to.

I'm enable to solve this error, i wanted to display listview of API data which is in large amount

Showing large data in listview,here is a paging show method.After getting API data, saving them in local CacheListData.Not directly set it to listView.ItemsSource .And you need create a ItemListData to add data from CacheListData.Which the count of added data according to you once want to show.When listview scroll to bottom ,then show Add More Swipe method to reload next page data.

Generally, Solution is to cache lagre data to local first.Then get data a little by page to show.Here is a solution link can refer to.


You are using the wrong endpoint, you should use this one, to retrieve a list of employees

 var RestURL = "http://dummy.restapiexample.com/api/v1/employees/";  

You can check the API documentation