我有一个简单的 Android 倒数计时器,其输出失真。我正在尝试创建一个简单的游戏,用户必须重复单击一个按钮,然后通过 8 个图像的过程将可绘制图像从一个更改为另一个。可绘制对象渲染得很好,但倒数计时器(应该从 30 秒开始)似乎会粘住和/或生成不代表当前经过的时间量的不正确数字。有没有人对为什么会发生这种情况或我应该调查什么来解决这个问题有任何建议?
MultitapGame.java
public class MultitapGame extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.multitapgame);
final View btn = findViewById(R.id.gameButton);
final View img = findViewById(R.id.game1);
final TextView mTextField = (TextView) findViewById(R.id.gameCDT);
final TextView mTextField2 = (TextView) findViewById(R.id.gameCDT2);
final View mTextField3 = findViewById(R.id.gameCDT3);
final View mTextField4 = findViewById(R.id.gameCDT4);
img.setBackgroundResource(R.drawable.image1);
btn.setOnClickListener(new OnClickListener() {
public int count = 0;
@Override
public void onClick(View v) {
setCount(getCount() + 1);
new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
int timeLeft = (int) (millisUntilFinished / 1000) ;
((TextView) mTextField).setText("seconds remaining: ");
final TextView mTextField2 = (TextView) findViewById(R.id.gameCDT2);
mTextField2.setText(String.valueOf(timeLeft + ""));
}
public void onFinish() {
int numTaps = count;
if(numTaps<150)
{
((TextView) mTextField3).setText("Unlucky chucky! ");
((TextView) mTextField4).setText("taps done: " + numTaps);
}
else
{
((TextView) mTextField3).setText("Congrats Bro :-) !");
((TextView) mTextField4).setText("taps done: " + numTaps);
}
}
}.start();
if(count==15)
{
img.setBackgroundResource(R.drawable.image2);}
if(count==30)
{
img.setBackgroundResource(R.drawable.image3);}
if(count==45)
{
img.setBackgroundResource(R.drawable.image4);}
if(count==60)
{
img.setBackgroundResource(R.drawable.image5);}
if(count==75)
{
img.setBackgroundResource(R.drawable.image6);}
if(count==90)
{
img.setBackgroundResource(R.drawable.image5);}
if(count==100)
{
img.setBackgroundResource(R.drawable.image6);}
if(count==110)
{
img.setBackgroundResource(R.drawable.image5);}
if(count==115)
{
img.setBackgroundResource(R.drawable.image6);}
if(count==118)
{
img.setBackgroundResource(R.drawable.image5);}
if(count==121)
{
img.setBackgroundResource(R.drawable.image6);}
if(count==123)
{
img.setBackgroundResource(R.drawable.image5);}
if(count==125)
{
img.setBackgroundResource(R.drawable.image6);}
if(count==126)
{
img.setBackgroundResource(R.drawable.image5);}
if(count==127)
{
img.setBackgroundResource(R.drawable.image6);}
if(count==130)
{
img.setBackgroundResource(R.drawable.image7);}
if(count==140)
{
img.setBackgroundResource(R.drawable.image1);}
if(count==160)
{
Intent i = new Intent();
i.setClassName("com.B00512756.angertwo",
"com.B00512756.angertwo.Strategies");
startActivity(i);
finish();}
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
});
}
}