如何在 OncreateView 中运行异步功能?

2024-01-19

我的应用程序有问题。首先,我使用以下命令制作了两个选项卡碎片这会膨胀一个activity。实现的选项卡工作正常。其次我已经展示了XAML right.

但是,我现在需要异步运行一些东西 Fragment 中的 OnCreateView。我怎样才能管理这个而不出现错误?

任何帮助是极大的赞赏!谢谢

这是我的片段:

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 
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 OncreateView 中运行异步功能? 的相关文章

随机推荐