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% を直接表示します。

プライベート ProgressBar mProgress; プライベート int mProgressStatus = 0;

プライベート ハンドラ mHandler = new Handler();

protected void onCreate(バンドルつらら) { 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(); }
于 2013-03-15T16:47:51.350 に答える