如何在正常程序中隐藏 progressbar
。我用了代码:
registerAsyncTask = new RegisteAsyncTask(infogateway,getApplicationContext());
pb.setVisibility(View.VISIBLE);
registerAsyncTask.execute(phone, name, null,gender,password, email, null,null,null,role,null,null);
我必须在哪里使进度条不可见?
答案 0 :(得分:1)
请查看官方指南AsyncTask。
protected void onPreExecute()
{
Log.d(LOG_TAG, "Pre-Execute");
super.onPreExecute();
pb.setVisibility( View.INVISIBLE);
}
private class doSomething extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
//Inflate you view or do anything here before loading stuff
}
protected Void doInBackground(Void... urls) {
//loading stuff
}
protected void onProgressUpdate(String... progress) {
//change your UI - like a progressbar
}
@Override
protected void onPostExecute(String unused) {
//Hide the progressbar
}
我希望它可以帮到你。
答案 1 :(得分:1)
尝试在onPreExecute()
中设置可见:
@Override
protected void onPreExecute() {
super.onPreExecute();
progress.setVisibility(View.VISIBLE);
}
并在onPostExecute()
完成任务后设置隐身:
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
progress.setVisibility(View.GONE);
}