Skip to content

Instantly share code, notes, and snippets.

View AreJay-Smith's full-sized avatar

RJ Smith AreJay-Smith

  • Voze
  • New York, New York
View GitHub Profile
@AreJay-Smith
AreJay-Smith / FragmentTransactionSansDestroy.kt
Created July 10, 2018 03:32
FragmentTransaction without destroying.
val MAP_FRAG_TAG = "mapFragTag"
val LIST_FRAG_TAG = "listFragTag"
fun manageFragmentTransaction(selectedFrag: String) {
when (selectedFrag) {
MAP_FRAG_TAG -> {
if (fragmentManager?.findFragmentByTag(MAP_FRAG_TAG) != null) {
//if the fragment exists, show it.
fragmentManager?.beginTransaction()?.show(fragmentManager?.findFragmentByTag(MAP_FRAG_TAG))?.commit();
} else {
@AreJay-Smith
AreJay-Smith / ReplaceFragment.kt
Last active July 17, 2018 20:01
Replace Fragment
// Create new fragment (Either map or list fragment) and the transaction
val listFragment = ListFragment()
val transaction = fragmentManager!!.beginTransaction()
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack if needed
transaction.replace(R.id.fragment_container, listFragment)
transaction.addToBackStack(null)
// Commit the transaction
@AreJay-Smith
AreJay-Smith / FragmentTransaction.kt
Last active July 10, 2018 03:35
Managing Fragments
val fragment = Fragment()
val fragmentManager = fragmentManager
val fragmentTransaction = fragmentManager!!.beginTransaction()
fragmentTransaction.replace(R.id.fragment_container, fragment)
fragmentTransaction.addToBackStack(null)
fragmentTransaction.commit()