I'm trying to pass an ArrayList<String>
as an argument while using safeArgs. But when I select ArrayList from the list of serializable and build, it is throwing me these exceptions
One type argument expected for class ArrayList<E : Any!>
One type argument expected. Use 'ArrayList<*>' if you don't want to pass type arguments
I get that I have to set the dataType for the ArrayList but I'm not able to do it nor do I have options while setting up the safeArgs from the Navigation graph screen.
In the Navigation graph XML, the code is generated as
<argument
android:name="teamsToAdd"
app:argType="java.util.ArrayList" />
is there a way to declare the dataType in the XML of the navigation graph?
Try this:
<argument
android:name="teamsToAdd"
app:argType="string[]" />
You can also generate this by checking the Array
option when generating an argument through the GUI:
As this will require a string array rather than a list, you can then convert your list to an array with:
parameterList.toTypedArray()
And back from an array with:
receivedArray.toList()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With