Skip to content

Instantly share code, notes, and snippets.

@koush
Created April 13, 2015 04:08
Show Gist options
  • Star 30 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save koush/cf4e16a8b4e292743a37 to your computer and use it in GitHub Desktop.
Save koush/cf4e16a8b4e292743a37 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