I am trying pass ArrayList data from one fragment to another fragment using safe args, here is the argument
<argument
android:name="upcomingEvents"
app:argType="com.x.Models.Event[]" />
but when I want to pass data using safe args, I have this error
it is said that
type mismatch.
required: Array<(out) Event!>
Found: ArrayList
how to convert ArrayList<Event>
to Array<(out) Event!>
?
and also vice versa , how to convert Array<(out) Event!>
to ArrayList<Event>
?
Kotlin has built in methods for both operations, namely, toTypedArray()
and asList()
:
val upcomingEvents = currentUserData!!.upcomingEvents
val array = upcomingEvents.toTypedArray()
// On the other side
val array = ...
val list = array.asList()