This code is in the code behind:
protected override async void OnAppearing()
{
base.OnAppearing();
listView.ItemsSource = await Service.DataAsync();
}
The class that fetches data:
public class Service
{
public List<TodoItem> TodoList { get; private set; }
static HttpClient client;
Service()
{
client = new HttpClient();
client.MaxResponseContentBufferSize = 256000;
}
public async Task<List<TodoItem>> DataAsync()
{
TodoList = new List<TodoItem>();
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();
TodoList = JsonConvert.DeserializeObject<List<TodoItem>>(content);
Debug.WriteLine(content);
}
}
catch (Exception ex)
{
Debug.WriteLine(@"ERROR {0}", ex.Message);
}
return TodoList;
}
}
When the class and task is static Im able to make this call and populate the listview but not without static. I dont want it to be static. Not duplcate.
and you return just List itself.
– Woj Nov 29 '18 at 12:20