Listen for when a Component is Shown for the First Time

前端 未结 6 1564
日久生厌
日久生厌 2021-01-07 22:29

I am trying to capture the very first moment when a component is shown on the screen without using \'dirty\' solutions as with use of a timer. Basically, I want to know the

6条回答
  •  梦毁少年i
    2021-01-07 23:07

    Using AncestorListener and ancestorAdded worked for me. Here's sample code:

    addAncestorListener(new AncestorListener() {
        @Override
        public void ancestorRemoved(AncestorEvent event) {}
    
        @Override
        public void ancestorMoved(AncestorEvent event) {}
    
        @Override
        public void ancestorAdded(AncestorEvent event) {
            // component is shown here
        }
    });
    

提交回复
热议问题