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

How to show a spinner/loader until the image gets downloaded?

$
0
0

Hello everybody,

I need to show a loader/spinner in place of my ImageView until the image gets downloaded. Currently, there is only a blank space shown and the image is displayed once totally downloaded. This is what I currently have:

        private void DisplayQrCode(String uriString)
        {
            WebClient web = new WebClient ();
            web.DownloadDataCompleted += new DownloadDataCompletedEventHandler(web_DownloadDataCompleted);
            web.DownloadDataAsync (new Uri(uriString));
        }

        void web_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {

            if (e.Error != null)
            {
                RunOnUiThread(() =>
                              Toast.MakeText(this, e.Error.Message, ToastLength.Short).Show());
            }
            else
            {
                Bitmap bm = BitmapFactory.DecodeByteArray(e.Result, 0, e.Result.Length);

                RunOnUiThread(() =>
                {
                    ImageView imgQrCode = FindViewById<ImageView>(Resource.Id.imgQrCode);
                    imgQrCode.SetImageBitmap(bm);
                });
            }
        }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



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