Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing ArrayList as argument in safeArgs

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?

like image 318
Anirudh Ganesh Avatar asked Jun 02 '20 04:06

Anirudh Ganesh


1 Answers

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:

enter image description here

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()
like image 87
CampbellMG Avatar answered Oct 12 '22 22:10

CampbellMG