Issue
Is there a way to handle a view visibility change (say, from GONE to VISIBLE) without overriding the view?
Something like View.setOnVisibilityChangeListener();
?
Solution
You can use a GlobalLayoutListener
to determine if there are any changes in the views visibility.
myView.setTag(myView.getVisibility());
myView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int newVis = myView.getVisibility();
if((int)myView.getTag() != newVis)
{
myView.setTag(myView.getVisibility());
//visibility has changed
}
}
});
Answered By - Nicolas Tyler
Answer Checked By - David Goodson (JavaFixing Volunteer)