Android 比较两个整数的困难。如何记住结果?

Android 比较两个整数的困难。如何记住结果?,android,int,comparison,counter,Android,Int,Comparison,Counter,这是我的密码。我需要做的是记住“count”的值并将其传输到“count1”,以便在计时器第二次启动时比较count和count1,因此如果count>count1,则发布“Great”,如果不是“Bad”。我不知道怎么做,我想在这种情况下需要第三个int,这就是为什么我添加了count3,但我不知道如何使用它。好的,我找到了一个解决方案 public class Tab1 extends Activity { int count = 0; int count1 = 0; int count3;

这是我的密码。我需要做的是记住“count”的值并将其传输到“count1”,以便在计时器第二次启动时比较count和count1,因此如果count>count1,则发布“Great”,如果不是“Bad”。我不知道怎么做,我想在这种情况下需要第三个int,这就是为什么我添加了count3,但我不知道如何使用它。

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

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) {

            }
    }
  };


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