当我的方法被调用时,我需要打开我的弹出屏幕,但它被我的等待忽略并且不显示弹出窗口。
这是一个 android 设备,我rg.plugins.popup
用来显示我的弹出页面,我使用 VS17 作为 IDE。
到目前为止,我还尝试同步调用我的方法,但这似乎也不起作用。
public async void PegaValor(bool retry)
{
await PopupNavigation.PushAsync(new Paginas.PopupTentarNovamente());
Paginas.PopupTentarNovamente tentarNovamente = new Paginas.PopupTentarNovamente();
if (tentarNovamente.resultado)
{
retry = false;
}
else
{
retry = true;
}
}
我怀疑需要在主 UI Dispatcher 上运行弹出窗口,我建议尝试以下操作:
public async void PegaValor(bool retry)
{
Activity.RunOnUiThread(async () => {
await PopupNavigation.PushAsync(new Paginas.PopupTentarNovamente());
});
Paginas.PopupTentarNovamente tentarNovamente = new Paginas.PopupTentarNovamente();
if (tentarNovamente.resultado)
{
retry = false;
}
else
{
retry = true;
}
}
编辑:
根据您的评论并快速查看您的 github 链接,这里有几种方法可以执行我的建议,尽管我仍然不知道您如何从 git 存储库实例化类。
因此,举一个简单的例子,这种方式假设您在活动中使用该类,因此您可以尝试以下操作
// Create an instance of metodosEmpenho in your activity and pass through the Activity as a parameter to the constructor.
public class MyActivity : Activity
{
private MetodosEmpenho metodosEmpenho;
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
metodosEmpenho = new MetodosEmpenho(Context as Activity);
metodosEmpenho.VerOperador("");
}
}
// Create a consturctor in the MetodosEmpenho class that will take the Activity paramter and store it for later use.
public class MetodosEmpenho
{
private readonly Activity _activity
public MetodosEmpenho(Activity currActivity)
{
_activity = currActivity;
}
public async void PegaValor(bool retry)
{
_activity.RunOnUiThread(async () => {
await PopupNavigation.PushAsync(new Paginas.PopupTentarNovamente());
});
Paginas.PopupTentarNovamente tentarNovamente = new Paginas.PopupTentarNovamente();
if (tentarNovamente.resultado)
{
retry = false;
}
else
{
retry = true;
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句