FragmentDirections不是由Safe Args插件生成的 [英] FragmentDirections was not generate by Safe Args plugin

查看:683
本文介绍了FragmentDirections不是由Safe Args插件生成的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用Safe Args插件从一个片段跳转到另一个片段时,编译器显示未解析的参考:VideoFragmentDirections". 我已经为安全的args设置了类路径和依赖关系,并且VideoFragmentArgs已正确生成. kotlin_version ='1.3.50' navigation-safe-args-gradle-plugin:2.1.0 在我的xml中

When I trying to use Safe Args plugin to jump from one fragment to another, the compiler shows "Unresolved reference: VideoFragmentDirections". I have already set the classpath and dependency for safe args and VideoFragmentArgs was generated correctly. kotlin_version = '1.3.50' navigation-safe-args-gradle-plugin:2.1.0 In my 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

And in 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)
            }
        })
}

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

Also, I had tried to clean and rebuild the project, it still doesn't work.

推荐答案

尝试

apply plugin: "androidx.navigation.safeargs.kotlin"

在应用程序build.gradle中

in app build.gradle

这篇关于FragmentDirections不是由Safe Args插件生成的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆