我正在尝试隐藏/显示ProgressBar根据AsyncTask状态, 我有两个类,一个扩展FragmentActivity和第二个AsyncTask。使用AsyncTask隐藏/显示ProgressBar
MainActivity.java
public class MainActivity extends FragmentActivity {
public static ProgressBar mProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
}
@Override
protected void onStart() {
super.onStart();
// What will happen to the progress bar here?
}
@Override
protected void onStop() {
super.onStop();
// What will happen to the progress bar here?
}
@Override
protected void onResume() {
super.onResume();
// What will happen to the progress bar here?
}
}
MyAsyncTask.java
public class MyAsyncTask extends AsyncTask<Void,Void, Void> {
@Override
protected Void doInBackground() {
// start download some images from cloud
// Here the progress bar should start to appear in MainActivity
// mProgressBar.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(Void result) {
Log.d(TAG, "Finished book downloading images the cloud");
// Here the progress bar should start to disappear in MainActivity
// mProgressBar.setVisibility(View.GONE);
}
}
main_activity.xml
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
希望你能理解我,谢谢大家谁可以提供帮助。
http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog?rq=1这可以解决你的问题。 – Android