比较两个整数的困难.如何记住结果


public class Tab1 extends Activity {
int count = 0;
int count1 = 0;
int count3;
private static final int MILLIS_PER_SECOND = 1000;
  private static final int SECONDS_TO_COUNTDOWN = 11;
  private Handler mHandler = new Handler();
  private CountDownTimer timer;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tab1);
    final TextView t11 = (TextView) findViewById(R.id.t11);
    final TextView t12 = (TextView) findViewById(R.id.t12);   
    t11.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
             t11.setText("10 seconds");
             count = 0; 
             mHandler.postDelayed(mUpdateTimeTask, 3000);
        }
    });
    Button butb1 =(Button)findViewById(R.id.butb1);
    butb1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            t12.setText("" + ++count);
        }
    });
}
@Override
protected void onDestroy() {
    super.onDestroy(); }
private void showTimer(int countdownMillis) {
      timer = new CountDownTimer(countdownMillis, MILLIS_PER_SECOND) {
      @Override
      public void onTick(long millisUntilFinished) {
          final TextView t11 = (TextView) findViewById(R.id.t11);
        t11.setText(" " +
        millisUntilFinished / MILLIS_PER_SECOND + "SECONDS");
      }
      @Override
        public void onFinish() {
          Button butb1 =(Button)findViewById(R.id.butb1);
          butb1.setVisibility(View.INVISIBLE); 
          timer.cancel();
          final TextView t11 = (TextView) findViewById(R.id.t11);
          if (count>count1)
            {
                t11.setTextSize(60);
                t11.setText("GREAT!");
            }
          else {
              t11.setText("BAD!");}
        }
      }.start();
    }
 private Runnable mUpdateTimeTask = new Runnable() {
    public void run() {
        Button butb1 =(Button)findViewById(R.id.butb1);
        butb1.setVisibility(View.VISIBLE);
        try {
              showTimer(SECONDS_TO_COUNTDOWN * MILLIS_PER_SECOND);
            } catch (NumberFormatException e) {
            }
    }
  };

}

这是我的代码。我需要做的是记住"count"的值并将其传输到"count1",以便在计时器第二次启动时比较count和count1,所以如果count>count1,则发布"很棒",如果不是 - "坏"。我不知道如何制作它,我想在这种情况下需要第三个 int,这就是我添加 count3 的原因,但我不知道如何使用它。

好的,我找到了一个解决方案

 if (count>count1)
      {
        count1 = count;         
    t21.setText("GREAT!");  }

相关内容

  • 没有找到相关文章

最新更新