0
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,則發佈「Great」,如果不是 - 「壞」。我不知道如何做到這一點,我猜在這種情況下需要第三個int,這就是爲什麼我加了count3,但我不知道如何使用它。比較兩個整數的困難。如何記住結果?