I feel like there's an more concise/elegant way to...
# android
j
I feel like there's an more concise/elegant way to write this.
Copy code
val index = fragmentList.indexOf(fragment)
        fragmentList[index] = NoDataFragment.newInstance()
am I missing something?
m
not sure if there is anything better, but you can turn this into a MutableList method and use it as
fragmentList.replace(fragment, NoDataFragment.newInstance())
. Something along the line of https://gist.github.com/mpotra/0dddfda9111408bc21041deaccc3c564
Or use
.replaceAll
but that iterates over the entire array