我的应用程序有问题。首先,我使用 fragments 制作了两个选项卡,这会膨胀一个 activity。实现的选项卡工作正常。其次,我已经正确显示了 XAML。
但是,我现在需要异步运行一些东西 fragment 中的 OnCreateView。我怎样才能在不出错的情况下管理它?
非常感谢任何帮助!谢谢
这是我的 fragment :
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;
}
}
最佳答案
这对我有用,感谢所有答案!
public override async void OnActivityCreated(Bundle savedInstanceState)
{
base.OnActivityCreated(savedInstanceState);
await LoadData();
}
private async Task LoadData()
{
//My async method
}
关于c# - 如何在 OncreateView 中运行一些异步的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47306649/