[英]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.