I have a FrameLayout and using the bottom navigation View there is a switching of 3 fragments. When the button is clicked, TextViews are created in the Main Fragment. The problem is that when switching from the main fragment to the second and returning to the main fragment, the created TextView disappears. How it can be solved. That is, I need the TextView to stay on the fragment
this is the code for replacing fragments, it is located in the MainActivity
fm = supportFragmentManager
binding.bottomNavigationView.setOnNavigationItemSelectedListener {
when(it.itemId){
R.id.roomsFragment -> {}
R.id.homeFragment -> {
fm.commit {
replace<HomeFragment>(R.id.framLayout)}
}
R.id.settingsFragment -> {
fm.beginTransaction().replace(R.id.framLayout, SettingsFragment.newInstance()).commit()
}
}
true
}
replacement takes place using MainActivity and the additional fragment does not have the code it is the main fragment