amanda.hinchman-dominguez
04/09/2018, 4:59 AMgildor
04/09/2018, 5:00 AMget all images in a fileWhat do you mean?
amanda.hinchman-dominguez
04/09/2018, 5:01 AMgildor
04/09/2018, 5:02 AMamanda.hinchman-dominguez
04/09/2018, 5:02 AMgildor
04/09/2018, 5:02 AMamanda.hinchman-dominguez
04/09/2018, 5:03 AMgildor
04/09/2018, 5:03 AMamanda.hinchman-dominguez
04/09/2018, 5:04 AMgildor
04/09/2018, 5:04 AMraw
resource diramanda.hinchman-dominguez
04/09/2018, 5:04 AMgildor
04/09/2018, 5:05 AMamanda.hinchman-dominguez
04/09/2018, 5:05 AMgildor
04/09/2018, 5:07 AM<array name="cards"> <item>R.drawable.clubs</item>
<item>R.drawable.hearts</item>
</array>
amanda.hinchman-dominguez
04/09/2018, 5:09 AMgildor
04/09/2018, 5:12 AMfun loadDrawables(arrayId: Int, res: Resources): List<Drawable> {
val icons = res.obtainTypedArray(arrayId)
val list = (0 until icons.indexCount).map {
icons.getDrawable(it)
}
icons.recycle() // Must recycle array after
return list
}
walk definitely cannot be done for a resource fileBut resources are flat, there is no directories, you probably can iterate through all the app resources, but it’s probably not the thing that you want to do, you want to iterate through specific group of resources
probably why it’s better to pull images from an API in the first placeThis is good question. Usually if images are big you load them from API, but for some types of apps it doesn’t make any sense, if those resources are static and required to run you app. Sometimes those images just dynamic (so you want to change them without app update) in this case load from network of course better solution. It’s always trade off, but I don’t think that grouping of images is somehow good argument to chose one of possible options
amanda.hinchman-dominguez
04/09/2018, 5:22 AMgildor
04/09/2018, 5:23 AM@ArrayRes
annotation to arrayId argument, it will decrease change of passing of different type resource id and function signature will be easier for understandingamanda.hinchman-dominguez
04/09/2018, 5:27 AMgildor
04/09/2018, 5:29 AM