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.
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
Here is my 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;
}
}
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With