Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need execute a method when the fragment is visible (to the user).

Example: I have 2 buttons (button 1 and button 2) , 2 fragments(fragment 1 and fragment 2) and the method loadImages() inside the class fragment 2.

when I press "button2" I want to replace fragment 1 by fragment 2 and then after the fragment 2 is visible (to the user) call loadImages().

I tried to use onResume() in the fragment class but it calls the method before the fragment is visible and it makes some delay to the transition.

I tried setUserVisibleHint() too and did not work.

A good example is the Instagram app. when you click on profile it loads the profile activity first and then import all the images.

I hope someone can help me. I will appreciate your help so much. Thank you.

share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.