进度条没有显示进度条

时间:2013-03-15 16:32:33

标签: android progress-bar progressdialog

我正在使用进度条,但它没有显示出连续的进展。它给出了一个绿色条,并没有显示持续的进展(即10次进展)。

private ProgressBar mProgress;
private int mProgressStatus = 0;

private Handler mHandler = new Handler();

protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setContentView(R.layout.fetchee_distance);
    mProgress = (ProgressBar) findViewById(R.id.p);

    Thread timer = new Thread() {
        public void run() {
            try {
                sleep(1000);
                while (mProgressStatus < 100) {
                    mProgress.setProgress(mProgressStatus);
                    // mProgress.setMax(100);
                    mProgressStatus += 10;

                    System.out.println("count" + mProgressStatus);

                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                /*
                 * Intent openMainList = new Intent(StartPoint.this,
                 * in.isuru.caf.MainList.class);
                 * startActivity(openMainList);
                 */
            }
        }
    };
    timer.start();
}

1 个答案:

答案 0 :(得分:1)

在循环中移动了睡眠线程,在你的代码中它首先睡眠,然后进入while循环,在那里它只是非常快速地完成迭代并导致直接显示完整的100%的条形,而不是睡觉

  

私人ProgressBar mProgress; private int mProgressStatus = 0;

     

private Handler mHandler = new Handler();

     

protected void onCreate(Bundle icicle){       super.onCreate(冰柱);

setContentView(R.layout.fetchee_distance);
mProgress = (ProgressBar) findViewById(R.id.p);

Thread timer = new Thread() {
    public void run() {
        try {

            while (mProgressStatus < 100) {
                  sleep(1000);//Sleep moved to while thread
                mProgress.setProgress(mProgressStatus);
                // mProgress.setMax(100);
                mProgressStatus += 10;

                System.out.println("count" + mProgressStatus);

            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            /*
             * Intent openMainList = new Intent(StartPoint.this,
             * in.isuru.caf.MainList.class);
             * startActivity(openMainList);
             */
        }
    }
};
timer.start(); }