H3ll0 H3ll0 - 1 year ago 71
Android Question

Why does this program not loop when a button is clicked?

I am having issues trying to loop a part of a program I have developed. There are 9 random strings of different colors, and 9 random colors of the corresponding string. For example a red "Yellow" may be displayed. I have buttons of each of the 9 colors, and the user gets a point added to their score each time a button of the color the string represents is pressed. I know that the scoring works just fine, I have tested it and a point is awarded at the tight time. My issue is that once a colored button is pressed, I intend for a new randomly colored random string to be outputted. This does not happen, the same string of same color remains on the screen. Here is the relevant code:

I would like it to loop whenever the user clicks any button, right or wrong. Thanks in advance for any help.

Answer Source

if (true) {

This is entirely useless. It does nothing. true will always be equal to true, so this will never affect your program. I wouldn't be surprised if it's optimized out entirely.

You likely intended to write

while (true) {

But, since you managed to mix up if and while (assuming that's what the problem is), I STRONGLY urge you to take a step back and review the basics before going any further. Make sure you understand exactly what if and while (at the very least) do.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download