2013-03-15 294 views
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(); 
} 
+1

我想你的睡眠應該在你的循環中 – njzk2 2013-03-15 16:40:42

回答

1
在循環

感動睡眠線程,在你的代碼就先睡覺,然後在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(); }