title: android how to make listener to a custom variable?
body: <p>i've seen this thread : <a href="https://stackoverflow.com/questions/5941960/android-how-to-implement-listener">How to implement a listener</a> about implement listeners.</p>
  
  <p>its actually pretty simple but i don't get how exactly its done and how to implement in my own code.</p>
  
  <p>i have this static variable variable: AppLoader.isInternetOn.
  i want to build a listener which will listen to this variable changes and update a TextView.</p>
  
  <p>should i do this: ?</p>
  
  <p>build an interface:</p>
  
  <pre><code>public interface InternetStateListener {
       public void onStateChange();
  }
  </code></pre>
  
  <p>run it in my activity:</p>
  
  <pre><code>public class MyActivity extends Activity {
  private InternetStateListener mListener;
  
  setTheListener(this);
  
  public void setTheListener(InternetStateListener listen) {
      mListener = listen;
  }
  
  private void onStateChange() {
      if (mListener != null) {
         if (AppLoader.isInternetOn)
          text.setText("on")
         else
          text.setText("off")
      }
    }
  }
  </code></pre>