【发布时间】:2011-12-17 15:22:41
【问题描述】:
我正在尝试在下载一些内容时更新 AsyncTask 中的进度条..
这是代码:
@Override
protected void onPreExecute() {
Intent myIntent = new Intent(mContext, Explanation.class);
mContext.startActivity(myIntent);
View inflater = View.inflate(mContext, R.layout.explanation, null);
mProgressDialog = (ProgressBar) inflater.findViewById(R.id.Explanation_ProgressBar);
}
@Override
protected void onProgressUpdate(Integer... values) {
mProgressDialog.setProgress(values[0]);
}
xml:
<ProgressBar
android:max="100"
style="?android:attr/progressBarStyleHorizontal"
android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:id="@+id/Explanation_ProgressBar"
android:layout_height="wrap_content"></ProgressBar>
注意:进度条位于我在 onPreExecute() 中调用的 Activity 的布局中。我想通过 AsyncTask 更新它。这可能吗?为什么不更新?
【问题讨论】:
-
我认为它可能必须在主线程上修改 ui 元素。
-
AsyncTask 是否应该处理所有线程的东西?
-
别管我以前的cmets我读错了你的问题