If you post a code snippet, ALWAYS USE CODE TAGS:
How to use code tags: Using code tags properly
Generally, separate processing of the button click itself (the “intent”) from doing the work (the “action”).
-
always gather the click of the button
-
if you CAN do it (logic located far away from the button), then do the action
-
if you cannot do it, then don’t do it, or perhaps make a different sound
Once you have that working, then you can easily make something else to control this field on the button: