2012-06-19 175 views
1

我希望進度條在與字符串匹配時增加。就像如果我點擊是的話,yes欄會增加。但由於某種原因,我無法取得進展。如何進度進度條

代碼:

public class result extends VoteActivity{ 

     private ProgressBar mProgress; 
    private int mProgressStatus = 0; 

    private Handler mHandler = new Handler(); 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.alert); 
if(choice=="Yes") 
{ 
     mProgress = (ProgressBar) findViewById(R.id.p1); 

     // Start lengthy operation in a background thread 
     new Thread(new Runnable() { 
      public void run() { 

        ++mProgressStatus; 


        // Update the progress bar 
        mHandler.post(new Runnable() { 
         public void run() { 
          mProgress.setProgress(mProgressStatus); 
         } 
        }); 

      } 
     }).start(); 
} 

我在做什麼錯在這裏?

回答

5

您無法將字符串與==進行比較。您需要使用equals()

if(choice.equals("Yes")) 
+0

@Floem謝謝你,但之後模擬器強制關閉,當我點擊Yes時 –

+0

@Samrat:你在哪裏定義'choice'?你可以發佈你的onClickListener嗎? – Floern

+0

@Floem我在另一個類/ Activity中定義了選擇,並在這裏導入該類並使用該String變量。我希望當我的字符串返回是時,yes的進度條應該繼續。 –

1

你試過做a.equals("Yes"),而是做了參考的比較?

0

除了@Floem你可能想看看使用AsyncTask。 如果您在後臺進程之前或之後想要更新UI線程,這將會派上用場。

另一件事情就是完全符合你的要求,並避免所有要發佈的電話號碼是CountDownTimer。雖然你可能沒有顯示你的計數數字,但你當然可以用它作爲暫停。