简体   繁体   English

进度栏上未显示进度

[英]progress bar not showing progress on bar

I'm using progress bar but it is not showing contineous progress. 我正在使用进度条,但没有显示连续的进度。 It gives a green bar and does not show continuous progress (ie 10 times progress). 它显示绿色条,并且不显示连续进度(即进度的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();
}

Moved sleep thread in the loop, in you're code it first sleeps and then goes in the while loop where it just goes really quick through the iteration and results in directly showing the full 100% of the bar, instead of sleeping. 在循环中移动了睡眠线程,在您编写代码时,它首先进入睡眠状态,然后进入while循环,在循环过程中,它真的非常快地通过了迭代,并导致直接显示全部100%的小节,而不是处于睡眠状态。

private ProgressBar mProgress; 私人ProgressBar mProgress; private int mProgressStatus = 0; private int mProgressStatus = 0;

private Handler mHandler = new Handler(); 私有处理程序mHandler = new Handler();

protected void onCreate(Bundle icicle) { super.onCreate(icicle); 受保护的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(); } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM