Reputation: 1164
I am using navigation components but cannot get the Args class generated so I can use it in my destination Fragment
the following way:
private val myArgs by navArgs<MyDestFragmentArgs>()
// later in code access properties from args
username = myArgs.username
I see that MySourceFragmentDirections
was generated so I assume the plugin is used correctly. I tried cleaning and rebuilding the project in Android Studio but don't see any *Args classes generated.
My nav_graph.xml
contains:
<fragment
android:id="@+id/mySourceFragment"
android:name="com.example.MySourceFragment"
android:label="@string/nav_title_source"
tools:layout="@layout/source_fragment">
<action
android:id="@+id/action_to_dest"
app:destination="@id/myDestFragment">
<argument
android:name="username"
app:argType="string" />
</action>
</fragment>
Upvotes: 0
Views: 284
Reputation: 1164
I realized that my nav_graph.xml
did not have correct format (the argument
element should be inside of the destination fragment, not inside an action
element defined in the source fragment) as below:
<fragment
android:id="@+id/mySourceFragment"
android:name="com.example.MySourceFragment"
android:label="@string/my_source_screen_title"
tools:layout="@layout/my_source_fragment">
<action
android:id="@+id/action_to_dest"
app:destination="@+id/myDestinationFragment" />
</fragment>
<fragment
android:id="@+id/myDestinationFragment"
android:name="com.example.MyDestinationFragment"
android:label="@string/my_dest_screen_title"
tools:layout="@layout/my_dest_fragment">
<argument
android:name="username"
app:argType="string" />
</fragment>
Upvotes: 1