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
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 { |
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
// 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 |
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
val fragment = Fragment() | |
val fragmentManager = fragmentManager | |
val fragmentTransaction = fragmentManager!!.beginTransaction() | |
fragmentTransaction.replace(R.id.fragment_container, fragment) | |
fragmentTransaction.addToBackStack(null) | |
fragmentTransaction.commit() |