Last active
August 29, 2015 14:26
-
-
Save basilbeltran/88ca4647147a40895cca to your computer and use it in GitHub Desktop.
FragmentActivity abstracted
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 abstract class MFragmentActivity extends FragmentActivity { | |
protected abstract Fragment createFragment(); | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_fragment); | |
FragmentManager fm = getSupportFragmentManager(); | |
Fragment fragment = fm.findFragmentById(R.id.fragmentContainer); | |
if (fragment == null) { | |
fragment = createFragment(); // createFragment() the implemented method | |
fm.beginTransaction().add(R.id.fragmentContainer, fragment).commit(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment