title: Disable a button while processing and re-enable after processing - Java (android studio)
body: <p>I am coding an android app using android studio(Java) that controls an LED(for now) via Bluetooth using Arduino.</p>
  <p><strong>Goal:</strong> I want the button (btn5) to be locked/ disabled after first click while executing its code then automatically unlock/enable again after execution. btn5 must process its code once only when clicked even if there are multiple clicks on the button.</p>
  <p><strong>Problem:</strong> The LED blinks 5 times on one click, but if clicked multiple times it blinks 10, 15... times. I've tried to implement what was advised on other similar threads but it does not get me to my goal. it only enables the button again when I reload the app.</p>
  <p>The closest I got was disabling btn5 once it is clicked which remains disabled until btn4 is pressed as below:</p>
  <pre><code>btn4.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick (View v) {
              btn5.setEnabled(true);
              sendSignal(&quot;0&quot;);
          }
      });
  
      btn5.setOnClickListener(new View.OnClickListener() {
          int i= 0;
          int p= 5;
  
          @Override
          public void onClick (View v) {
  
              while (i!=p)
              {
                  sendSignal(&quot;1&quot;);
                  btn5.setEnabled(false);
                  i=i+1;
                  try {
                      Thread.sleep(500);
                  } catch (InterruptedException ie) {
                      Thread.currentThread().interrupt();
                  }
  
                  sendSignal(&quot;0&quot;);
                  try {
                      Thread.sleep(500);
                  } catch (InterruptedException ie) {
                      Thread.currentThread().interrupt();
                  }
  
              }
                  sendSignal(&quot;0&quot;);
                  i=0;
  
          }
  
  
      });
  </code></pre>
  <p>Please, any assistance would be appreciated as I am new to java and app building.</p>