Adrian Geanta
Adrian Geanta

Reputation: 115

Android studio problems with onclick

So..I want that on every 100 clicks or 1000 points (same thing) to show that toast.. I have this code

public void DestroyTheCube(View v) {
        points = points + 10;
        castig.setText("Points: " + points);
        if (points == 100  ) {
            Toast.makeText(Activ1.this,"Merge",Toast.LENGTH_SHORT).show();
        }
    }

But it's dosen't work, because if I have more than 100 points the toast will never show again.. "DestroyTheCube" it's a onclick from a ImageButton. Can you please help me with this problem?

Upvotes: 0

Views: 28

Answers (1)

Will
Will

Reputation: 2191

What you are looking for is points % 1000 == 0. The % is the modulo operator and returns the remainder of a / b. Checking that the remainder is 0 is the same as checking that a is evenly divisible by b.

Upvotes: 2

Related Questions