Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How can I display a progress bar while API returns the results

$
0
0

Hello everyone, I'm a newbie to Xamarin Android and C#,

I want to display a progress bar(rotating circle) until the web API returns the results, How can I achieve this?

I have the following on button click event,

btnSubmit.Click += (sender, e) =>
{
var jobId = txtJobID.Text;

            var request = HttpWebRequest.Create(string.Format("http://192.168.79.174:90/api/test/" + jobId));
            request.ContentType = "application/json";
            request.Method = "GET";

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {

                    if (response.StatusCode != HttpStatusCode.OK)
                        Console.Out.WriteLine("Error fetching data. Server returned status code: {0}", response.StatusCode);

                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        var content = reader.ReadToEnd();

                        dynamic arr = JsonConvert.DeserializeObject(content);

                        foreach (dynamic obj in arr)
                        {
                            tvJobID.Text = obj.JobID;
                            tvJobType.Text = obj.JobType;
                            tvDueDate.Text = obj.DueDate;
                            tvVisitTime.Text = obj.Time;
                            tvVisitStatus.Text = obj.VisitStatus;
                            tvAddress1.Text = obj.Address1;
                            tvAddress2.Text = obj.Address2;
                            tvPostCode.Text = obj.PostCode;
                            tvAuthority.Text = obj.Authority;
                        }

                        if (content == null || content == "" || content == "[]")
                        {

                            //Console.Out.WriteLine("Response contained empty body...");
                            layoutController.Visibility = ViewStates.Invisible;
                            Toast.MakeText(ApplicationContext, "Invalid Job ID or no visits for this ID. Please try again", ToastLength.Long).Show();
                        }
                        else
                        {
                            layoutController.Visibility = ViewStates.Visible;


                        }
        }
              }

        };

I have this progress bar in the .axml




Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>