Created
March 11, 2016 03:34
-
-
Save ronbeltran/f24d6fd81617582fbb0a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.ronbeltran.projectname; | |
import android.os.Bundle; | |
import android.support.v4.app.Fragment; | |
import android.support.v4.app.FragmentActivity; | |
import android.support.v4.app.FragmentManager; | |
public abstract class SingleFragmentActivity extends FragmentActivity { | |
protected abstract Fragment createFragment(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_fragment); | |
FragmentManager fm = getSupportFragmentManager(); | |
Fragment fragment = fm.findFragmentById(R.id.fragment_container); | |
if (fragment == null) { | |
fragment = createFragment(); | |
fm.beginTransaction() | |
.add(R.id.fragment_container, fragment).commit(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment