0

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.

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);
    }

}

and in my activity I'm setting everything up like this:

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
        }

    });     
}

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 (like here), 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 =)

Community
  • 1
  • 1
codingNewb
  • 470
  • 1
  • 8
  • 23

1 Answers1

0

What about tbt.setAfterDrawListener(null);?

SimonSays
  • 10,867
  • 7
  • 44
  • 59
  • lol really? Here I thought I'd have to make a bunch of new code and remove it like the globallayoutlistener does. I'll give this a shot, thanks =) – codingNewb Apr 10 '14 at 01:04