gpt4 book ai didi

android - FragmentDirections 不是由 Safe Args 插件生成的

转载 作者:行者123 更新时间:2023-12-05 00:10:32 27 4
gpt4 key购买 nike

当我尝试使用 Safe Args 插件从一个 fragment 跳转到另一个 fragment 时,编译器显示“未解析的引用:VideoFragmentDirections”。我已经为安全参数设置了类路径和依赖项,并且正确生成了 VideoFragmentArgs。kotlin_version = '1.3.50'导航安全参数 gradle 插件:2.1.0在我的 xml 中

<fragment
android:id="@+id/nav_home"
android:name="example.ui.home.HomeFragment"
android:label="@string/menu_home"
tools:layout="@layout/fragment_home" >
<action
android:id="@+id/action_nav_home_to_videoFragment"
app:destination="@id/videoFragment"
app:popUpTo="@+id/nav_home"/>
</fragment>
<fragment
android:id="@+id/videoFragment"
android:name="example.ui.videoui.VideoFragment"
android:label="VideoFragment" >
<argument
android:name="id"
app:argType="long"
android:defaultValue="0L" />
</fragment>

在 HomeFragment.ky 中

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val videoViewModel = ViewModelProviders
.of(this)
.get(HomeViewModel::class.java)
val adapter = video_list.adapter!! as PlaylistAdapter
videoViewModel.videos.observe(this, Observer<List<Video>> {
adapter.submitList(it)
adapter.onItemClickListener = View.OnClickListener { v ->

val viewHolder = v.tag as RecyclerView.ViewHolder
val position = viewHolder.adapterPosition
val id = it[position].id
val action = VideoFragmentDirections.actionhHomeToVideo(id)
view.findNavController().navigate(action)
}
})
}

此外,我曾尝试清理并重建项目,但仍然无法正常工作。

最佳答案

// Project level build.gradle 
buildscript {
repositories {
google()
}
dependencies {
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version") //add here.
}
}

// Module level build.gradle.
plugins {
id 'androidx.navigation.safeargs'// add here.
}

祝你天天开心🙏

关于android - FragmentDirections 不是由 Safe Args 插件生成的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59035069/

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