显示Acr用户对话框加载程序,直到方法xamarin表单结束(android) [英] Show Acr User Dialogs loader until end of method xamarin forms (android)

查看:112
本文介绍了显示Acr用户对话框加载程序,直到方法xamarin表单结束(android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的xamarin表单项目(android和ios)上使用ShowLoading()Acr UserDialogs(v5.2.2),但在启动await方法之前并不会启动加载程序,最后也不会隐藏加载程序.

我的代码在ios上运行,但在android上什么都没发生.

示例

async Task MyMethod()
{
  UserDialogs.Instance.ShowLoading("Loading",MaskType.Black);
  await ViewModel.LoadData();
  UserDialogs.Instance.HideLoading();
}

//InsideViewModel
public async Task LoadData();
{
await Task.Yield(); //without this code and ios doesnt work
//download data
}

我在MainActivity.cs上为android UserDialogs.Init(this)添加了

有什么需要帮助的吗? 谢谢

解决方案

我编写了一些代码,这些代码在Acr用户对话框中确实非常快速并且可以完美地工作.

我使用去污服务,这是我的完整示例代码.

PCL代码

    void CallService ()
    {
        Device.BeginInvokeOnMainThread (() => UserDialogs.Instance.ShowLoading ("Loading ...", MaskType.Black));
        Task.Run (async () => {
            await DependencyService.Get<IJsonMethods> ().Load ("SERVICE_URL");
        }).ContinueWith (result => Device.BeginInvokeOnMainThread (() => {

            UserDialogs.Instance.HideLoading ();

            }
        })
        );
    }

界面

public interface IJsonMethods
{
    Task Load(string url);
}

依赖服务

public async Task Load (string url)
    {
        try{
            using (var http = new HttpClient (new NativeMessageHandler ())) {
                var x = await http.GetAsync (new Uri (url));
                string res = await x.Content.ReadAsStringAsync ();
                MainViewModel.JsonList = JsonConvert.DeserializeObject<ArticleClass.RootObject> (res);
            }
        }catch (Exception ex) {
            MainViewModel.JsonList = null;
        }
    }

I use ShowLoading() Acr UserDialogs (v5.2.2) on my xamarin forms project (android and ios) but i wont start loader before start await method and Hide Loader with the end.

My code working on ios but on android nothing happened.

example

async Task MyMethod()
{
  UserDialogs.Instance.ShowLoading("Loading",MaskType.Black);
  await ViewModel.LoadData();
  UserDialogs.Instance.HideLoading();
}

//InsideViewModel
public async Task LoadData();
{
await Task.Yield(); //without this code and ios doesnt work
//download data
}

I add for android UserDialogs.Init(this) on MainActivity.cs

Any help please ? Thanks

解决方案

I write some code where is really fast and working perfect with Acr User dialogs.

I use depedency service and here is my full sample code.

PCL code

    void CallService ()
    {
        Device.BeginInvokeOnMainThread (() => UserDialogs.Instance.ShowLoading ("Loading ...", MaskType.Black));
        Task.Run (async () => {
            await DependencyService.Get<IJsonMethods> ().Load ("SERVICE_URL");
        }).ContinueWith (result => Device.BeginInvokeOnMainThread (() => {

            UserDialogs.Instance.HideLoading ();

            }
        })
        );
    }

Interface

public interface IJsonMethods
{
    Task Load(string url);
}

Dependency Service

public async Task Load (string url)
    {
        try{
            using (var http = new HttpClient (new NativeMessageHandler ())) {
                var x = await http.GetAsync (new Uri (url));
                string res = await x.Content.ReadAsStringAsync ();
                MainViewModel.JsonList = JsonConvert.DeserializeObject<ArticleClass.RootObject> (res);
            }
        }catch (Exception ex) {
            MainViewModel.JsonList = null;
        }
    }

这篇关于显示Acr用户对话框加载程序,直到方法xamarin表单结束(android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆