java - Call a method when fragment is visible to user -


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

Example: I button 2 (button 1 and button 2), 2 pieces (piece 1 and piece 2) and method loadImages () within square pieces 2.

When I want to change "2 button" to piece 2 with Piece 2 and then user after the slice 2 (to call) loadImages () .

I the ribs in the fragment square () but this method calls the method before the fragment appears and it does some delay in infection.

I tried setUserVisibleHint () also did not work.

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

I hope someone I can greatly appreciate your help Thank you.

I'm a little confused about what I'm trying to do with you. It looks like the images are loading too fast for you ... Does this mean that your pictures are ready to be displayed? And this is a bad thing?

My guess (and this is just an estimate) is that Instagram does not have a profile picture in memory, so they have to do an API call to make them, which is why they appear on a delay If this is the case for you, consider starting the onResume method in asyncTask of the piece. Do whatever you need to load for images in the background, and then show the images on the main thread in the on-PostExtact callback. Ensure that you only start work if the images have not been loaded already.

However, if you have already loaded the images in memory, and you have a delay before the user comes in front of you, then you can post delayed method Handler . Something like this:

  new handler (). Post Delayed (New Runnabal) {@Override Public runs zero () {loadImages ();}}, 1000);  

Edit

As it says, handler code is too bad. I meant that this is a quick example, but it is very wrong I should not have included it in the first place would be a more complete answer:

  Personal handler handler; Resume on public null () {super. Rebirth (); If (handler == empty) {handler = new handler (); Handler. PostDelayed (New Runnabel) {@Override public void run ()} {loadImages ();}}, 1000); }} Public void onDestroyView () {super.onDestroyView (); Handler.removeCallbacksAndMessages (zero); Handler = null; }  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -