我试图同时下载一些东西,以更新的AsyncTask进度条..
下面是代码:进度条的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()中调用的活动的布局中。我想通过AsyncTask进行更新。这可能吗?为什么不更新?
我认为它可能必须做如何UI元素应该在主线程上进行修改。 –
实际上试试这个http://stackoverflow.com/questions/4836716/how-to-make-activity-ui-changes-from-an-android-asynctask –
不应该的AsyncTask处理所有线程的东西? – Omar