Last active
September 27, 2017 15:58
-
-
Save youngam/2f9dc59909231d277536ee2d4fa174ed to your computer and use it in GitHub Desktop.
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
class MainActivity : AppCompatActivity() { | |
private lateinit var fragmentContainer: ViewGroup | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
fragmentContainer = findViewById(R.id.fragment_container) as ViewGroup | |
} | |
public fun navigate(from: Fragment? = null, to: Fragment, addToBackStack: Boolean = true) { | |
if(from != null) from.userVisibleHint = false | |
val transaction = supportFragmentManager.beginTransaction() | |
.add(fragmentContainer.id, to) | |
if(addToBackStack) transaction.addToBackStack(null) | |
transaction.commit() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment