Tuesday, 25 September 2018

When does setVisibility() not fire onVisibilityChanged() in a view?

I have a problem where in a specific situation when I call setVisibility(GONE) inside my custom view, its onVisibilityChanged method doesn't get called and it actually doesn't hide the view although getVisibility() returns 8 (or GONE) afterwards.

Here is how I know the visibility changes but onVisibilityChanged is not called.

@Override
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
    Log.i(LOG_TAG, "onVisibilityChanged: " + visibility);
    super.onVisibilityChanged(changedView, visibility);
}

@Override
public void setVisibility(int visibility) {
    super.setVisibility(visibility);
    Log.i(LOG_TAG, "setVisibility: " + visibility);
}

public void hide(){
    Log.i(LOG_TAG, "before hide visibility: " + getVisibility());
    setVisibility(GONE);
    Log.i(LOG_TAG, "after hide visibility: " + getVisibility());
}

Normally when I call hide() I see these lines in the log:

before hide visibility: 0

onVisibilityChanged: 8

setVisibility: 8

after hide visibility: 8

But in a spicific situation when I call hide() I get these lines in the log and the view isn't hidden afterwards although getVisibility() returns 8:

before hide visibility: 0

setVisibility: 8

after hide visibility: 8

So when in general does this happen? When does setVisibility not call onVisibilityChanged?

Don't ask what my specific situation is. But please provide every general situation where this might happen.



from When does setVisibility() not fire onVisibilityChanged() in a view?

No comments:

Post a Comment