David B
David B

Reputation: 315

Binding to a Xamarin Listview via web service

I am trying to launch a interface method and bind it to a Xamarin list view but I am having some trouble. My interface is below

  readonly string url = "http://myinternaliis/api/";
  readonly IHttpService httpService;

  public ApiClient(IHttpService httpService)
  {
       this.httpService = httpService;
  }

  public Task<List<JobsList>> GetJobs() => httpService.Get<List<JobsList>>($"{url}job");

I am trying to bind it to my list view as such please correct me if this is wrong. Should I be creating a collection of some description

public partial class JobsPage : ContentPage
{
    readonly string url = "http://myinternaliis/api/";
    public IHttpService httpService;
    public IApi FuleApiClient;

    public JobsPage ()
    {
        InitializeComponent ();

        FuelApiClient _client = new FuelApiClient(httpService);

        this.JobListing.ItemsSource =   _client.GetJobs();
    }

Upvotes: 0

Views: 29

Answers (1)

Fran&#231;ois
Fran&#231;ois

Reputation: 3274

You need to await your task.

public partial class JobsPage : ContentPage
    {
        readonly string url = "http://myinternaliis/api/";
        public IHttpService httpService;
        public IApi FuleApiClient;

        public JobsPage ()
        {
        InitializeComponent ();


         FuelApiClient _client = new FuelApiClient(httpService);

         SetItemSource();

        }

        private Task SetItemSource()
    .   {
    .       JobListing.ItemsSource =   await _client.GetJobs();
        }
    }

Upvotes: 1

Related Questions