title: How to show a loading gif while an APi is being called in xamarin android?
body: <p>I want to show a loading gif while the code is calling an API but I don't know how to do this.</p>
  
  <pre><code>using System;
  using Android.App;
  using Android.Widget;
  using Android.OS;
  using RestSharp;
  using Newtonsoft.Json;
  using Android.Util;
  using App4.Resources;
  using Newtonsoft.Json.Linq;
  using Org.Json;
  using System.Net;
  using System.IO;
  using System.Collections.Generic;
  using System.Globalization;
  using Android.Graphics;
  using Android.Content.Res;
  
  
  namespace App4
  {
  [Activity(Label = "App4", MainLauncher = true, Icon = "@drawable/icon")]
  public class MainActivity : Activity
  {
      EditText edtcpf;
      Button btnConsumer;
      TextView txtcpf;
      RestRequest cpf { get; set; }
      public RestClient consumer { get; set; }
      IRestResponse mensagemConsumer;
      TextView txtsobrenome;
      RestClient orderId { get; set; }
      RestRequest requestorderId { get; set; }
      IRestResponse answerorder { get; set; }
      TextView txtnome;
      TextView txtresp0;
      TextView txtresp1;
      TextView txtresp2;
      TextView txtresp3;
      TextView txtresp4;
      public List&lt;string&gt; lista;
      ListView mlistview;
  
  
      protected override void OnCreate(Bundle bundle)
      {
          base.OnCreate(bundle);
  
          // Set our view from the "main" layout resource
          SetContentView(Resource.Layout.Main);
          txtcpf = FindViewById&lt;TextView&gt;(Resource.Id.txtcpf);
          mlistview = FindViewById&lt;ListView&gt;(Resource.Id.listView2);
          txtnome = FindViewById&lt;TextView&gt;(Resource.Id.txtNome);
          edtcpf = FindViewById&lt;EditText&gt;(Resource.Id.edtcpf);
          btnConsumer = FindViewById&lt;Button&gt;(Resource.Id.btnConsumer);
          btnConsumer.Click += BtnConsumer_Click;
          lista = new List&lt;string&gt;();
      }
  
      private void BtnConsumer_Click(object sender, EventArgs e)
      {
          try
          {
  
              // API Consumer CPF
  
              consumer = new RestClient("https://qa.api-latam.whirlpool.com/v1.0/consumers");
              cpf = new RestRequest("/" + edtcpf.Text, Method.GET);
              cpf.AddHeader("Content-Type", "application/json; charset=utf-8");
              cpf.AddHeader("Authorization", "Bearer fed6b2f0-7aba-3339-9813-7fc9387e2581");
              mensagemConsumer = consumer.Execute(cpf);
              Pessoa pessoa = JsonConvert.DeserializeObject&lt;Pessoa&gt;(mensagemConsumer.Content);
              txtnome.Text = "Nome: " + pessoa.firstName + " " + pessoa.lastName;
  
  
                  // API Consumer service-orders
                  orderId = new RestClient("https://qa.api-latam.whirlpool.com/v1.0/consumers/");
              requestorderId = new RestRequest("/" + edtcpf.Text + "/service-orders", Method.GET);
              requestorderId.AddHeader("Content-Type", "application/json; charset=utf-8");
              requestorderId.AddHeader("Authorization", "Bearer fed6b2f0-7aba-3339-9813-7fc9387e2581");
              answerorder = orderId.Execute(requestorderId);
              var requestToken = JsonConvert.DeserializeObject&lt;RootObject&gt;(answerorder.Content);
              var end = "";
  
              for (var i = 0; i &lt; requestToken.orders.Count; i++)
              {
                  end = requestToken.orders[i].order.orderId + " " + "StatusCode" + " - " + requestToken.orders[i].order.orderStatusCode + " "
                 + "Status Description: " + " - " + requestToken.orders[i].order.orderStatusDescription;
                  lista.Add(end);
                  ArrayAdapter&lt;string&gt; adapter = new ArrayAdapter&lt;string&gt;(this, Android.Resource.Layout.SimpleListItem1, lista);
                  mlistview.Adapter = adapter;
              }
          }
  </code></pre>
  
  <p>I tried to do a while beucase while(pessoa = null)... show the gif, but I couldn't. I downloaded this gif <a href="https://i.stack.imgur.com/MEBIB.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MEBIB.gif" alt="Loading gif"></a> to use it.
  So what I'm trying to do is: <strong>after clicking on the button "Consulta API" the App shows the loading and stop showing it when the API returns the context</strong>.</p>