I have written a custom view in android. I need to do some processing when visibility of this view is changed. Is there some listener which is called when visibility of a view/widget is changed ?
Edit:
I know how to change the visibility, would like to know if there is a listener which is called when we setVisibility on the view!
Do you want to do that processing within your custom view class? If so, then why not just override the setVisibility() method, call super(), and then do your custom processing?
I know how to change the visibility, would like to know if there is a listener which is called when we setVisibility on the view!
you have to subclass your view/widget
and override setVisibility
, and register a interface on which you will recive the notification. For instance:
public class MyView extends View {
public interface MyListener {
public void onSetVisibilityCalled();
}
public void registerListener(MyListener myListener) {
this.mListener = myListener;
}
public void setVisibility (int visibility) {
super.setVisibility(visibility);
if (mListener != null)
mListener.onSetVisibilityCalled();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With