Skip to content

Instantly share code, notes, and snippets.

@RohitSurwase
Last active December 4, 2017 11:35
Show Gist options
  • Save RohitSurwase/6656a3b2ec508dbd9dcf2b3ea691d8bf to your computer and use it in GitHub Desktop.
Save RohitSurwase/6656a3b2ec508dbd9dcf2b3ea691d8bf to your computer and use it in GitHub Desktop.
Calling Viewpager Fragment's Function on it's Visibility - Solid Solution.
private boolean notFirstTime;
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser && notFirstTime) {
//TODO: Call function to be executed every time.
requestData();
}
}
@Override
public void onResume() {
super.onResume();
notFirstTime = true;
if (getUserVisibleHint()) {
//TODO: Call function to be executed every time.
requestData();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment