MainActivity で SettingsListFragment から移動するにはどうすればよいですか?
<fragment
android:id="@+id/settings_list_fragment"
android:name="com.mandarine.targetList.features.settings.SettingsListFragment"
android:label="@string/settings"
tools:layout="@layout/fragment_settings_list">
</fragment>
私のナビゲーション グラフでは、MainActivity から画面を表示していないためです。1 つのアクティビティにあるナビゲーション全体、コードを確認できます
class MainActivity : AppCompatActivity(), MainActivityViewContract {
private lateinit var auth: FirebaseAuth
private lateinit var mAuthStateListener: FirebaseAuth.AuthStateListener
private val presenter = MainActivityPresenter(contract = this)
private lateinit var appBarConfiguration: AppBarConfiguration
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
signIn()
setupViews()
}
override fun onSupportNavigateUp(): Boolean {
return findNavController(R.id.nav_host_fragment).navigateUp(appBarConfiguration)
}
override fun onResume() {
super.onResume()
auth.addAuthStateListener(mAuthStateListener)
}
override fun onPause() {
super.onPause()
auth.removeAuthStateListener(mAuthStateListener)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
presenter.onActivityResult(requestCode, resultCode)
}
override fun cancelSignIn() {
finish()
}
private fun setupViews() {
val host: NavHostFragment = supportFragmentManager
.findFragmentById(R.id.nav_host_fragment) as NavHostFragment? ?: return
val navController = host.navController
appBarConfiguration = AppBarConfiguration(navController.graph)
val drawerLayout: DrawerLayout? = findViewById(R.id.drawer_layout)
appBarConfiguration = AppBarConfiguration(
setOf(R.id.target_list, R.id.settings_list_fragment, R.id.calendar_fragment),
drawerLayout
)
setupActionBar(navController, appBarConfiguration)
setupNavigationMenu(navController)
setupBottomNavMenu(navController)
}
private fun setupNavigationMenu(navController: NavController) {
val sideNavView = findViewById<NavigationView>(R.id.nav_view)
sideNavView?.setupWithNavController(navController)
}
private fun setupActionBar(
navController: NavController,
appBarConfig: AppBarConfiguration
) {
setupActionBarWithNavController(navController, appBarConfig)
}
private fun setupBottomNavMenu(navController: NavController) {
val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottom_navigation_view)
bottomNavigationView?.setupWithNavController(navController)
}
private fun signIn() {
auth = FirebaseAuth.getInstance()
mAuthStateListener = FirebaseAuth.AuthStateListener { firebaseAuth ->
presenter.signIn(activity = this, user = firebaseAuth.currentUser)
}
}
}