我想在填充datagrid時使用進度對話框,但出現以下錯誤:「Only創建一個視圖層次可以觸摸的意見」原來的線程,這是我的代碼,我希望他們能幫助我帶有進度對話框的Xamarin Android中的錯誤「只有創建視圖層次結構的原始線程可以觸及其視圖」
public async void RelacionClientesREST()
{
try
{
var dlg = ProgressDialog.Show(this, "Loading", "Cargando relación de usuarios");
ThreadPool.QueueUserWorkItem(d => {
RestClient client = new RestClient("http://portalclientewa.azurewebsites.net/api/RelacionClientes/");
var request = new RestRequest("GetData", Method.GET);
request.Timeout = 1500000;
request.RequestFormat = DataFormat.Json;
request.AddParameter("idP", Idp);
var temp = client.Execute(request).Content;
var parsedJson = JsonConvert.DeserializeObject(temp).ToString();
var lst = JsonConvert.DeserializeObject<List<ClientesProp>>(parsedJson).ToList();
dataGrid.ItemsSource = lst;
RunOnUiThread(() => {
dlg.Dismiss();
});
});
}
catch (Exception ex)
{
Toast.MakeText(this, "No hay datos registrados", ToastLength.Short).Show();
}
}