我在xamarin android中使用线程和进度条。我正在使用以下代码进行处理。但是线程完成后仍然显示进度条。 任何人都可以帮我解决这个问题:
ProgressBar probar=view.FindViewById<ProgressBar>(Resource.Id.progressBar1);
probar.Visibility = ViewStates.Invisible;
Button btnref = view.FindViewById<Button>(Resource.Id.btnrefresh);
btnref.Click += delegate {
probar.Visibility = ViewStates.Visible;
System.Threading.ThreadStart th = new System.Threading.ThreadStart(imagesetting);
Thread myThread = new Thread(th);
myThread.Start();
probar.Visibility = ViewStates.Invisible;
};
private void imagesetting() {
string uri = "example.com/xxx.svc" + Vid + "";
-----
}
先谢谢, Manthiram C
答案 0 :(得分:4)
1)在主线程
上制作隐藏/显示概率的方法private void ShowProgressBar(bool show) {
RunOnUiThread(() => {
ProgressBar probar=view.FindViewById<ProgressBar>(Resource.Id.progressBar1);
probar.Visibility = show ? ViewStates.Visible : ViewStates.Invisible;
});
}
2)通过调用 ShowProgressBar(true)
启动任务线程之前显示概率btnref.Click += delegate {
ShowProgressBar(true);
System.Threading.ThreadStart th = new System.Threading.ThreadStart(imagesetting);
Thread myThread = new Thread(th);
myThread.Start();
};
3)在图像设置
结束时调用 ShowProgressBar(false)隐藏概率 private void imagesetting() {
string uri = "example.com/xxx.svc" + Vid + "";
*some code*
ShowProgressBar(false);
}