title: how to make a function() enable/disable using switch widget in android studio?
body: <p>I got a function called updateTv() in my program which will run as soon as the app is opened. Now what I want is to create a button which will enable and disable the function updateTv(), so when the app is opened, the function updateTv() should run only when the switch is on/enable and when the switch is off, it should be disabled.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>final Runnable updater = new Runnable() {
  
      public void run() {
          updateTv();
          push(mEMA);
  
      }
  
  };
  </code></pre>
  
  <p>after few suggestions, I tried this,</p>
  
  <pre><code>final Runnable updater = new Runnable() {
          public void run() {
              aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                  @Override
                  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                      if (isChecked) {
                          {updateTv();
                              push(mEMA);
                          }
                          aSwitch.setText("disable");
                      } else {
                          aSwitch.setText("enable");
                      }
                  }
              });
          }
      };
      final Handler mHandler = new Handler();
  </code></pre>
  
  <p>still there's a problem, whenever it is switched on, its runs only once</p>