Last active
February 9, 2018 08:27
-
-
Save daichan4649/6462232 to your computer and use it in GitHub Desktop.
Fragment へBACK押下時イベントを通知する (Android)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface BackPressedListener { | |
void onBackPressed(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Activity | |
@Override | |
public void onBackPressed() { | |
Fragment fragment = getFragmentManager().findFragmentByTag(""); | |
if (fragment != null && fragment instanceof BackPressedListener) { | |
((BackPressedListener) fragment).onBackPressed(); | |
} else { | |
super.onBackPressed(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fragment (implements BackPressedListener) | |
@Override | |
public void onBackPressed() { | |
//TODO BACK押下時処理 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. your code doesn't work on nested fragment sir. can you help me for this quastion?