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,但我不知道如何使用它。
答案 0 :(得分:0)
好的,我找到了解决方案
if (count>count1)
{
count1 = count;
t21.setText("GREAT!"); }