Xamarin Android中未显示进度对话框

时间:2019-07-19 11:30:56

标签: xamarin xamarin.android

我在我的Xamarin Android应用程序中使用ZXing nuget扫描QR码。扫描后我已经添加了加载程序。我根据扫描数据调用api。但是api需要时间。我已经为Display loader编写了代码,但是它正在显示。我的代码有什么问题?

我的代码是:

 private void HandleScanResult(ZXing.Result result)
 {
      //scanner closed here.
     RunOnUiThread(() =>
    {
        try
        {
            progressDialog.Indeterminate = true;
            progressDialog.SetProgressStyle(ProgressDialogStyle.Spinner);
            progressDialog.SetIcon(Resource.Drawable.Icon);
            progressDialog.SetMessage("Contacting server. Please wait...");
            progressDialog.SetCancelable(false);
            progressDialog.Show();
        }
        catch { }
    });
    //API call
    progressDialog.Hide();
 }

在ScanButton上,单击代码:

imageBtn.Click += async delegate
            {
                var result = await scanner.Scan();
                RunOnUiThread(() => scanner.Cancel());
                HandleScanResult(result);
            };

0 个答案:

没有答案