简体   繁体   English

为什么我不能通过导航组件中的全局操作传递 arguments?

[英]Why I can´t pass arguments with global action in navigation component?

I´m trying to pass an argument with an global action from one destination to another.我正在尝试将具有全局操作的参数从一个目的地传递到另一个目的地。 I saw this method on the inte.net but it don´t work for any reasons and I can´t find a solution for it.我在 inte.net 上看到了这种方法,但由于任何原因它不起作用,我找不到解决方案。 I would be thankful for any help.如果有任何帮助,我将不胜感激。 How I´m trying to pass the argument:我如何尝试传递论点:

epoxyController = EventListEpoxyController { eventClickedID ->
        val navDirections = NavGraphDirections.actionGlobalEventHolder(eventID = eventClickedID)
        findNavController().navigate(navDirections)

I added an argument to the eventholder destination in my navgraph and also added an global action.我在导航图中向事件持有者目的地添加了一个参数,还添加了一个全局操作。 But for some reasons I can´t find a value for it the word is red and the error is like但由于某些原因,我找不到它的值,这个词是红色的,错误就像

Named arguments are not allowed for non-Kotlin functions Cannot find a parameter with this name: eventID < Thats how my navgraph looks like:非 Kotlin 函数不允许名为 arguments 找不到具有此名称的参数:eventID < 这就是我的导航图的样子:

<fragment
    android:id="@+id/eventHolder"
    android:name="de.n.newtest.ui.Fragments.Details.EventHolderKT"
    android:label="fragment_event_holder">
    <argument
        android:name="eventid"
        android:defaultValue="-1"
        app:argType="integer" />
<action
    android:id="@+id/action_global_eventHolder"
    app:destination="@id/eventHolder"
    app:enterAnim="@anim/holderslideinright"
    app:exitAnim="@anim/holderslideoutleft"
    app:popEnterAnim="@anim/holderslideinleft"
    app:popExitAnim="@anim/holderslideoutright">

What did I miss?我错过了什么?

val navDirections = NavGraphDirections.actionGlobalEventHolder(eventID = eventClickedID)

The eventID is created by the IDE to illustrate that this parameter is the callback parameter that points to eventClickedID , and it's not supposed to write it yourself as the error implies: eventID由 IDE 创建,说明这个参数是指向eventClickedID的回调参数,不能自己写,报错:

 Named arguments are not allowed for non-Kotlin functions Cannot find a parameter with this name: eventID < Thats how my navgraph looks like:

So, you just need to remove it:所以,你只需要删除它:

epoxyController = EventListEpoxyController { eventClickedID ->
        val navDirections = NavGraphDirections.actionGlobalEventHolder(eventClickedID)
        findNavController().navigate(navDirections)
}

You're using android:name="eventid" .您正在使用android:name="eventid" That means that the named parameter for actionGlobalEventHolder is eventid , not eventID .这意味着actionGlobalEventHolder的命名参数是eventid ,而不是eventID

You'll want to either change your android:name to eventID or update your code to use eventid .您需要将android:name更改为eventID或更新您的代码以使用eventid

Of course, using a named argument is never a requirement, so you could leave it out entirely.当然,使用命名参数从来都不是必需的,因此您可以完全不使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当参数具有默认值时,为什么我不能使用导航组件将参数传递给片段? - Why can't I pass an argument to fragment using navigation component when that argument has a default value? Android 导航组件“全局操作”问题 - Android Navigation Component 'global action'' issue 使用导航组件将参数安全地传递给嵌套图 - Pass arguments safely to nested graph with Navigation Component Android 导航组件:在片段中传递值(参数) - Android Navigation Component : Pass value (arguments) in fragments Android 导航组件 - 为什么要在导航图中添加参数? - Android Navigation Component - Why add arguments in the navigation graph? 带参数的导航组件 .popBackStack() - Navigation Component .popBackStack() with arguments 如何使用底部导航视图和 Android 导航组件将参数传递给片段? - How to pass arguments to a fragment using bottom navigation view and Android Navigation component? 导航组件无法弹出以退出应用程序 - Navigation Component can't pop to exit app 为什么我不能在 Android 应用程序中删除操作栏? - Why can't I remove Action Bar in the Android app? 导航组件参数默认值 - Navigation component arguments default value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM