In a Xamarin project, Android - I am new to android development. While working on a activity, in the OnCreate
method am setting a custom Adapter for a ListView
.
protected async override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView(Resource.Layout.Main);
var listAdapter = new CustomListAdapter(this);
//.................................................
listView = (ListView) FindViewById(Resource.Id.list);
// populate the listview with data
listView.Adapter = listAdapter;
}
In the ctor
of the adapter, creating a list of items in async call.
public CustomListAdapter(Activity context) //We need a context to inflate our row view from
: base()
{
this.context = context;
// items is List<Product>
items = await GetProductList();
}
Since Getproducts is a async call, it will load the data asynchronously.
The problem is once i set the adapter to the list it will try invoke the GetView
method of adapter. At that time, items will not be loaded. so there is a null exception.
How to handle this situation.
Thanks.