在回调方法中设置适配器时,Xamerin Android ListView未填充

在回调方法中设置适配器时,Xamerin Android ListView未填充,listview,xamarin.android,xamarin,Listview,Xamarin.android,Xamarin,我试图通过使用Web服务加载数据来填充ListView 我在回调方法中设置ListView适配器的代码。但在这种情况下,适配器GetView覆盖方法未启动&列表视图未填充。 但当我在OnCreate(Bundle)方法中使用虚拟数据设置适配器时,它就可以工作了。 有人知道我错过了什么吗?我需要在这里调用任何UI更新方法吗 protected List<Product> Products { get; set; } protected void FillProductList

我试图通过使用
Web服务加载数据来填充
ListView
我在
回调方法
中设置ListView
适配器
的代码。但在这种情况下,适配器
GetView覆盖方法
未启动&列表视图未填充。

但当我在OnCreate(Bundle)方法中使用虚拟数据设置适配器时,它就可以工作了。
有人知道我错过了什么吗?我需要在这里调用任何UI更新方法吗

  protected List<Product> Products { get; set; }

  protected void FillProductListCallBack(List<Product> products)
   {
      if (products.Any())
      {
        Products = products;
        ProductListView = FindViewById<ListView>(Resource.Id.lstList);
        ProductListView.Adapter = new ProductScreenAdapter(this, Products);
        ProductListView.SetBackgroundColor(Color.Red);
      }
   }
受保护的列表产品{get;set;}
受保护的无效FillProductListCallBack(列出产品)
{
if(products.Any())
{
产品=产品;
ProductListView=FindViewById(Resource.Id.lstList);
ProductListView.Adapter=新产品屏幕适配器(此,产品);
ProductListView.SetBackgroundColor(颜色:红色);
}
}

回调可能会从UI线程返回,这会导致您的问题。尝试这样做:

protected List<Product> Products { get; set; }

protected void FillProductListCallBack(List<Product> products)
{
    if (products.Any())
    {
        RunOnUiThread(() => 
        {
            Products = products;
            ProductListView = FindViewById<ListView>(Resource.Id.lstList);
            ProductListView.Adapter = new ProductScreenAdapter(this, Products);
            ProductListView.SetBackgroundColor(Color.Red);
        });
    }
}
受保护的列表产品{get;set;}
受保护的无效FillProductListCallBack(列出产品)
{
if(products.Any())
{
RunOnUiThread(()=>
{
产品=产品;
ProductListView=FindViewById(Resource.Id.lstList);
ProductListView.Adapter=新产品屏幕适配器(此,产品);
ProductListView.SetBackgroundColor(颜色:红色);
});
}
}