gpt4 book ai didi

android - 如何在 findNavController().navigate() 中发送带方向的导航器附加功能

转载 作者:行者123 更新时间:2023-12-05 00:04:40 25 4
gpt4 key购买 nike

我要为我的 View 设置什么过渡动画

搜索它并了解 must send navigator extras in navigate metod

它对正常导航有效,但是当使用导航发送参数时显示此错误

None of the following functions can be called with the arguments supplied:private open fun navigate(p0: NavDestination, p1: Bundle?, p2: NavOptions?, p3: Navigator.Extras?): Unit defined in androidx.navigation.NavControllerpublic open fun navigate(p0: Int, p1: Bundle?, p2: NavOptions?, p3: Navigator.Extras?): Unit defined in androidx.navigation.NavController

关于第一个参数错误

这是我的代码

val extras = FragmentNavigatorExtras(image_cover to "image_cover")
findNavController().navigate(
MoviesFragmentDirections.actionMoviesFragmentToMovieItemFragment(
moviesEntity.title,
moviesEntity.image,
moviesEntity.text,
moviesEntity.video
),
null,
null,
extras
)

最佳答案

您可以使用以下“导航”函数变体来发送添加到 NavDirections 的额外内容:

 /**
* Navigate via the given {@link NavDirections}
*
* @param directions directions that describe this navigation operation
* @param navigatorExtras extras to pass to the {@link Navigator}
*/
public void navigate(@NonNull NavDirections directions,
@NonNull Navigator.Extras navigatorExtras) {
navigate(directions.getActionId(), directions.getArguments(), null, navigatorExtras);
}

像这样修改您的代码以实现:

val extras = FragmentNavigatorExtras(image_cover to "image_cover")
findNavController().navigate(
MoviesFragmentDirections.actionMoviesFragmentToMovieItemFragment(
moviesEntity.title,
moviesEntity.image,
moviesEntity.text,
moviesEntity.video
),
extras
)

关于android - 如何在 findNavController().navigate() 中发送带方向的导航器附加功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62776673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com