I do the above code in OnCreate method of this fragment that's supposed to run before the OnCreateView as far as I know.
Problem: The call to awaitable REST method is not awaited.
When debugging line by line it goes like this:
OnCreate is called. Processed to the line where I call the awaitable method (that is supposed to fill listofarticles) and simply skips to the OnCreateView. Therefore listofarticles is null.
OnCreateView is called and processed. At this point program just goes back to the activity it's called.
I can no longer debug it because Xamarin Studio thinks I'm finished but at the emulator it just starts to call the REST method after all this and because of that the data inside listofarticles is useless because I can't pass it to Adapter now.
Why is this happening and how to fix it??
<p>public class LatestNewsFragment : Android.Support.V4.App.Fragment, ListView.IOnItemClickListener<br />
private Context globalContext = null;<br />
private List<Article> listofarticles;<br />
private ArrayAdapter<Article> listAdapter;</p>
this.RetainInstance = true;
public async override void OnCreate (Bundle savedInstanceState)
globalContext = this.Context;
//Create a progress dialog for loading
ProgressDialog pr = new ProgressDialog(globalContext);
var rest = new RestAccess();
//Download the data from the REST API
listofarticles = await rest.ListArticlesAsync ("SomeSource");
listAdapter = new ArrayAdapter<Article>(globalContext, Android.Resource.Layout.SimpleListItem1, listofarticles);
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
var view = inflater.Inflate(Resource.Layout.Fragment_LatestNews, null);
ListView listView = view.FindViewById<ListView>(Resource.Id.list_latestnews);
listView.Adapter = listAdapter;
listView.OnItemClickListener = this;