title: android - remove custom callback from view?
body: <p>so, kind of confused on using callbacks and I'm hoping someone could hopefully help me out :). I've made a quick custom view that uses a callback to signal my activity once an ondraw is done. </p>
  
  <pre><code>import android.content.Context;
  import android.graphics.Canvas;
  import android.view.View;
  
  public class CustomViewCallBackTest extends View {
  
      AfterDraw callback;
  
      public interface AfterDraw {
          public void afterViewDrawn(Object myEventData);
      }
  
      public void setAfterDrawListener(AfterDraw callback) {
          this.callback = callback;
      }
  
  
      @Override
      protected void onDraw(Canvas canvas) {
          super.onDraw(canvas);
          //callback.afterViewDrawn(myEventData);
      }
  
      public CustomViewCallBackTest(Context context) {
          super(context);
      }
  
  }
  </code></pre>
  
  <p>and in my activity I'm setting everything up like this:</p>
  
  <pre><code>CustomViewCallBackTest tbt;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      tbt.setAfterDrawListener(new AfterDraw() {
  
          @Override
          public void afterViewDrawn(Object myEventData) {
              // TODO Auto-generated method stub
          }
  
      });     
  }
  </code></pre>
  
  <p>so I have a callback that I can use fairly easily, my question becomes how would I remove this callback? Something like android does with it's GlobalLayoutListener (i.e. getViewTreeObserver().removeOnGlobalLayoutListener(this)).  I've seen a couple answers that address removing callbacks from a handler (<a href="https://stackoverflow.com/questions/5883635/how-to-remove-all-callback-from-a-handler">like here</a>), but I'm not familiar enough yet to know how to apply anything to my situation. I'd sure appreciate it if someone could show me how to remove my own custom callback =)</p>