进度条未显示进度条

问题描述:

我正在使用进度条,但未显示持续进度。它给出了一个绿色的横条,并没有显示持续的进展(即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

我想你的睡眠应该在你的循环中 – njzk2 2013-03-15 16:40:42

在循环

感动睡眠线程,在你的代码就先睡觉,然后在while循环中去的地方,它只是经过迭代非常快,并导致直接显示栏的全部100% ,而不是睡觉。

private ProgressBar mProgress; private int mProgressStatus = 0;

private Handler mHandler = new Handler();

保护无效onCreate(Bundle冰柱){ 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(); }