Skip to content
Advertisement

Change text in button

JavaScript

I need to make it so that if a user clicks on button_apple and doesn’t click on it for 3 seconds, its text becomes so superfluous. And if anyone knows why my text changes in button_apple, but not in button_cherry. Tell me, please.

Advertisement

Answer

You’re setting the listener on your apple button. The cherry button doesn’t have a listener on it.

Reconsider what you’re trying to achieve and simplify it.

If the user clicks the apple button you need to do something.

If the user clicks the cherry button you need to do something (maybe something else).

If the user clicks the watermellon button, … and so on.

JavaScript

EDIT

To make something happen after a set amount of time you have to consider:

  1. the inputs: which objects / variables influence the action
  2. the output: what’s supposed to happpen if all inputs are valid
  3. the duration

With android you could use a handler. See the postDelayed method.

JavaScript

All of this stuff has to be inside the click listener with the logic you need to implement.

“If a user clicks on button apple and doesn’t click on it for three seconds”

You could do something like

JavaScript

I didn’t test this so you’ll probably have to modify it a bit but that’s the general idea.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement