I have a TextView that displays a number (in this case, the number is 10).
Now, i have a button so the user has to press that button 10 times in order for the number to hit 0, resulting in moving on to the next level. However,
I can keep hitting that button and it starts its way back into the negatives (-1, -2, etc.).
I tried to think of how I would prevent this but I’m at loss.. any ideas?
———————————–EDIT—————————————–
Okay, so here is my update (I got it to stop at 0):
public void onClick(View v) {
// TODO Auto-generated method stub
if (scr >= 1) {
scr = scr - 1;
TextView Score = (TextView) findViewById(R.id.Score);
Score.setText(String.valueOf(scr));
}
if (scr == 10)
{
aCounter.start();
}
if (scr == 1)
{
aCounter.cancel();
new AlertDialog.Builder(Tap_Game_Activity.this)
.setTitle("Congratulations!").setMessage("Go to Level 2?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface AlertDialog, int PositiveButton) {
setContentView(R.layout.activity_level02_activity);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface AlertDialog, int NegativeButton) {
}
}).show();
}
}});
}
(EDIT!): I fixed the AlertDialog by changing the 2 ‘Else If’ statements to just ‘If’ statements. However, my timer still doesn’t work :(, any help?
suppose number is the variable you are showing in the TextView, consider following code,