AsyncTask进度轮不旋转吗? [英] AsyncTask progress wheel not spinning?

查看:54
本文介绍了AsyncTask进度轮不旋转吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做 zip 解压缩下载文件将XML中的数据存储到数据库中时,AsyncTask可以正常工作 strong>.

AsyncTask work fine when I'm doing zip , unzip , download file and store data from XML into database.

但是现在我正在尝试实现 https://github.com/fry15/uk.co.jasonfry.android.tools 在布局中滑动(从数据库中选择数据并在webview中显示),这会在运行时添加布局,因此需要很长时间,因此我可以将其放置在AsyncTask中,但是现在AsyncTask进度轮不旋转?

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 ?

我的代码运行正常,但是问题不是AsyncTask上的问题.

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()函数,该函数返回视图

    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;

}

推荐答案

您是否要在UI线程之外操纵UI? 您需要使用 Handler 将要执行的任务排队来自后台线程的UI线程.

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.

有关与UI线程通信的信息.

这篇关于AsyncTask进度轮不旋转吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆