Skip to content

Instantly share code, notes, and snippets.

@IRMobydick
Forked from koush/MyFragment.java
Last active August 29, 2015 14:19
Show Gist options
  • Save IRMobydick/a9cc37db6fc37f35f4cb to your computer and use it in GitHub Desktop.
Save IRMobydick/a9cc37db6fc37f35f4cb to your computer and use it in GitHub Desktop.
public class MyFragment {
boolean loaded;
private void maybeLoad() {
if (!loaded && getUserVisibleHint()) {
loaded = true;
loadMyData();
}
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
maybeLoad();
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
maybeLoad();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment