1

我希望进度条在匹配字符串时增加。就像我点击是,是的栏会增加。但由于某种原因,我无法让它取得进展。

代码:

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();
}

我在这里做错了什么?

4

3 回答 3

5

您不能将字符串与==. 您需要使用equals()

if(choice.equals("Yes"))
于 2012-06-19T19:02:12.207 回答
1

您是否尝试过a.equals("Yes"),而是比较了参考文献?

于 2012-06-19T19:01:49.693 回答
0

除了@Floem,您可能还想看看使用AsyncTask。如果在后台进程之前或之后您想要更新 UI 线程,这将派上用场。

另一件事完全符合您的要求并避免所有对 post 的调用是CountDownTimer。虽然您可能不会显示您的计数数字,但您当然可以将其用作超时。

于 2012-06-19T19:08:14.117 回答