如何在OncreateView中运行异步操作? [英] How can I run something Async in OncreateView?
本文介绍了如何在OncreateView中运行异步操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序有问题.首先,我使用片段制作了两个标签,这些标签夸大了活动.实施的选项卡工作正常.其次,我显示了 XAML 权限.
I have a problem with my app. Firstly, I made two Tabs using fragments which inflates an activity. The tabs implemented is working fine. Secondly i have displayed the XAML right.
但是,我现在需要在片段中的OnCreateView.如何在不出错的情况下进行管理?
However, I now need to run something asynchronously in OnCreateView in the Fragment. How can i manage this without getting errors?
任何帮助将不胜感激!谢谢
Any help is greatly appreciated! Thanks
这是我的片段:
public class FragmentSettings : SupportFragment
{
private Button mBtnOk;
public FragmentSettings(Context context)
{
mContext = context;
}
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
//Inflate the fragment XML
View view = inflater.Inflate(Resource.Layout.FragmentSettings, container, false);
//Grab the butten from the inflated fragment
mBtnOk = view.FindViewById<Button>(Resource.Id.mBtnOk);
mBtnOk.Click += (object sender, EventArgs e) =>
{
//DO stuff
};
//=====================================
//Want to do something async stuff here
//=====================================
return view;
}
}
推荐答案
这对我有用,谢谢您的所有回答!
This did the trick for me, thanks for all the answers!
public override async void OnActivityCreated(Bundle savedInstanceState)
{
base.OnActivityCreated(savedInstanceState);
await LoadData();
}
private async Task LoadData()
{
//My async method
}
这篇关于如何在OncreateView中运行异步操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文