1

我正在使用进度条,但它没有显示持续的进度。它给出一个绿色条并且不显示连续进度(即 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();
}
4

1 回答 1

1

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

私有进度条 mProgress;私有int mProgressStatus = 0;

私有处理程序 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 {

            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(); }
于 2013-03-15T16:47:51.350 回答