AsyncTask的进步不秒针轮纺纱? [英] AsyncTask progress wheel not spining?
问题描述
AsyncTask的做工精细,当我在做的拉链 解压 下载文件和存储数据从XML到数据库中
但现在我想实现 https://github.com/ fry15 / uk.co.jasonfry.android.tools 布局刷卡(数据来自数据库中选取并显示的WebView),这在运行时添加布局,它需要很长的时间,所以我可以把这个AsyncTask的,但现在的AsyncTask秒针轮进度不旋转?
我的code工作正常,但问题是没有在AsyncTask的纺车。
公共类LoadSlideAndQuestion扩展的AsyncTask<太虚,太虚,太虚> { ProgressDialog pDialog; 在preExecute保护无效(){
pDialog =新ProgressDialog(DialogBoxOnClick.this);
pDialog.setMessage(加载幻灯片和问题......);
pDialog.setCancelable(假);
pDialog.show(); } 保护无效doInBackground(虚空......未使用){ 意图I =新意图(DialogBoxOnClick.this,SlideScreen.class);
startActivity(ⅰ);
完();
回报(NULL);
} @覆盖
保护无效onProgressUpdate(虚空......值){
// TODO自动生成方法存根
super.onProgressUpdate(值);
} 保护无效onPostExecute(虚空未使用){
pDialog.dismiss();
}}
SlideActivity
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
的setContentView(R.layout.temp);
显示显示= getWindowManager()getDefaultDisplay()。
宽度= display.getWidth();
话题= getIntent()getSerializableExtra(名称)的toString()。
fetchdata(); 的PageControl mPageControl =(的PageControl)findViewById(R.id.page_control);
mSwipeView =(SwipeView)findViewById(R.id.swipe_view); mSwipeView.setPageControl(mPageControl); 的for(int i = 0; I<最大;我++){
mSwipeView.addView(新的FrameLayout(本));
} 的for(int i = 0; I<最大;我++){ ((的FrameLayout)mSwipeView.getChildContainer()。getChildAt(I))
.addView(setupView函数());
算上++;
}
}
setupView函数()函数返回的意见
公开查看setupView函数(){ LayoutInflater layoutInflator = getLayoutInflater();
的LinearLayout childlayout =(的LinearLayout)layoutInflator.inflate(
R.layout.webview,自动开关机,FALSE); QUESTION_NUMBER =(TextView中)childlayout
.findViewById(R.id.question_number);
question_type =(TextView中)childlayout.findViewById(R.id.question_type);
question_parameters =(TextView中)childlayout
.findViewById(R.id.question_parameter);
question_correct_answer =(TextView中)childlayout
.findViewById(R.id.question_correct_answer);
question_difficulty =(TextView中)childlayout
.findViewById(R.id.question_difficulty);
NEWOBJECT =新Questionclass();
NEWOBJECT = XmlHandler.questionlist.get(计数);
的System.out.println(newObject.QUESTION_NUMBER +新对象); questionView =(的WebView)childlayout.findViewById(R.id.Que_View);
WebSettings webSettings = questionView.getSettings();
// webSettings.setTextSize(WebSettings.TextSize.NORMAL);
webSettings.setDefaultFontSize(23); question_number.setText(newObject.QUESTION_NUMBER);
question_type.setText(newObject.QUESTION_TYPE);
question_correct_answer.setText(newObject.QUESTION_CORRECT_ANSWER);
question_parameters.setText(newObject.QUESTION_PARAMETERS);
question_difficulty.setText(newObject.QUESTION_DIFFICULTY); questionView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); questionView.getSettings()setRenderPriority(RenderPriority.HIGH)。
。questionView.getSettings()setCacheMode(WebSettings.LOAD_NO_CACHE); questionView.clearView();
questionView.loadDataWithBaseURL(
,
IntegralParse.htmlParse(newObject.QUESTION_ code,
到/ mnt / SD卡/ CHECK_LESSON_QUESTIONS /+主题+/+主题
+/+ newObject.QUESTION_NUMBER,
getApplicationContext(),宽)
+<小时/>中
+ IntegralParse.htmlParse(newObject.QUESTION_SOL_ code,
到/ mnt / SD卡/ CHECK_LESSON_QUESTIONS /+主题+/
+主题+/
+ newObject.QUESTION_NUMBER,
getApplicationContext(),宽),text / html的
UTF-8,);
questionView.requestLayout();
返回childlayout;}
您试图操纵UI线程之外的用户界面?
您需要使用 处理程序
的排队任务从后台线程执行UI线程上。
在与UI线程通信的更多信息。
AsyncTask work fine when I'm doing zip , unzip , download file and store data from XML into database.
But now I'm trying to implement https://github.com/fry15/uk.co.jasonfry.android.tools swipe in layout(data pick from database and show in webview) which add layout in run time so it takes a long time so I can put this in AsyncTask but now AsyncTask progress wheel not spinning ?
My code is working properly but problem is not spinning wheel on AsyncTask.
public class LoadSlideAndQuestion extends AsyncTask<Void, Void, Void> {
ProgressDialog pDialog;
protected void onPreExecute() {
pDialog = new ProgressDialog(DialogBoxOnClick.this);
pDialog.setMessage("Loading Slide and Questions...");
pDialog.setCancelable(false);
pDialog.show();
}
protected Void doInBackground(Void... unused) {
Intent i = new Intent(DialogBoxOnClick.this, SlideScreen.class);
startActivity(i);
finish();
return (null);
}
@Override
protected void onProgressUpdate(Void... values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
}
protected void onPostExecute(Void unused) {
pDialog.dismiss();
}
}
SlideActivity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.temp);
Display display = getWindowManager().getDefaultDisplay();
width = display.getWidth();
topic = getIntent().getSerializableExtra("name").toString();
fetchdata();
PageControl mPageControl = (PageControl) findViewById(R.id.page_control);
mSwipeView = (SwipeView) findViewById(R.id.swipe_view);
mSwipeView.setPageControl(mPageControl);
for (int i = 0; i < max; i++) {
mSwipeView.addView(new FrameLayout(this));
}
for (int i = 0; i < max; i++) {
((FrameLayout) mSwipeView.getChildContainer().getChildAt(i))
.addView(setupView());
count++;
}
}
setupView() function which returns views
public View setupView() {
LayoutInflater layoutInflator = getLayoutInflater();
LinearLayout childlayout = (LinearLayout) layoutInflator.inflate(
R.layout.webview, Switcher, false);
question_number = (TextView) childlayout
.findViewById(R.id.question_number);
question_type = (TextView) childlayout.findViewById(R.id.question_type);
question_parameters = (TextView) childlayout
.findViewById(R.id.question_parameter);
question_correct_answer = (TextView) childlayout
.findViewById(R.id.question_correct_answer);
question_difficulty = (TextView) childlayout
.findViewById(R.id.question_difficulty);
newObject = new Questionclass();
newObject = XmlHandler.questionlist.get(count);
System.out.println(newObject.QUESTION_NUMBER + " NEW OBJECT");
questionView = (WebView) childlayout.findViewById(R.id.Que_View);
WebSettings webSettings = questionView.getSettings();
// webSettings.setTextSize(WebSettings.TextSize.NORMAL);
webSettings.setDefaultFontSize(23);
question_number.setText(newObject.QUESTION_NUMBER);
question_type.setText(newObject.QUESTION_TYPE);
question_correct_answer.setText(newObject.QUESTION_CORRECT_ANSWER);
question_parameters.setText(newObject.QUESTION_PARAMETERS);
question_difficulty.setText(newObject.QUESTION_DIFFICULTY);
questionView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
questionView.getSettings().setRenderPriority(RenderPriority.HIGH);
questionView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
questionView.clearView();
questionView.loadDataWithBaseURL(
"",
IntegralParse.htmlParse(newObject.QUESTION_CODE,
"/mnt/sdcard/CHECK_LESSON_QUESTIONS/" + topic + "/" + topic
+ "/" + newObject.QUESTION_NUMBER,
getApplicationContext(), width)
+ "<hr/>"
+ IntegralParse.htmlParse(newObject.QUESTION_SOL_CODE,
"/mnt/sdcard/CHECK_LESSON_QUESTIONS/" + topic + "/"
+ topic + "/"
+ newObject.QUESTION_NUMBER,
getApplicationContext(), width), "text/html",
"utf-8", "");
questionView.requestLayout();
return childlayout;
}
Are you trying to manipulate the UI outside of the UI thread?
You need to use a Handler
to queue tasks for performing on the UI thread from a background thread.
More information on Communicating with the UI thread.
这篇关于AsyncTask的进步不秒针轮纺纱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!