1

Actually, i want to handle event transition between different fragment with same toolbar. i found this answer. They using addOnNavigatedListener , but in my case i didn't find this interface. I only have addOnDestinationChangedListener which didn't trigger transition between fragment. I want something like this:

navController.addOnNavigatedListener { controller, destination ->
            when(destination.id){
                R.id.action_nav_home_to_nav_search -> {
                    println("HOME TO SEARCH")
                    Timber.d("HOME TO SEARCH")
                    card_search.visibility = View.GONE
                }
                else -> {
                    println("HOME KE LAIN")
                    card_search.visibility = View.VISIBLE
                }
            }
        }

i using this dependencies:

    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.1'

Anyone know what happened?

Nanda Z
  • 1,604
  • 4
  • 15
  • 37
  • 1
    `addOnNavigatedListener` is a pre-1.0 alpha of Navigation (which was when that answer was added) and renamed to `addOnDestinationChangedListener`. How are you navigating between your fragments? Where are you adding your `OnDestinationChangedListener` (in your activity? Fragment?). Note that the IDs there are destination IDs, not action IDs like you have in your code. – ianhanniballake Nov 11 '20 at 05:13
  • @ianhanniballake youre right, destination id mean id of fragment. Thanks – Nanda Z Nov 11 '20 at 06:40

1 Answers1

4

Thanks to @ ianhanniballake, addOnNavigatedListener renamed to addOnDestinationChangedListener and the id should be fragment id

Nanda Z
  • 1,604
  • 4
  • 15
  • 37