Will Nixon
12/18/2019, 10:45 PM"@drawable/${formatString(entry)}"
Any thoughts on the best way to do this?Ben Abramovitch
12/18/2019, 10:51 PMWill Nixon
12/18/2019, 10:57 PMBen Abramovitch
12/18/2019, 10:57 PMWill Nixon
12/18/2019, 10:58 PMBen Abramovitch
12/18/2019, 10:59 PMWill Nixon
12/18/2019, 11:23 PMval uri = "@drawable/${formatString(entry)}"
val imageResource : Int = context.getResources().getIdentifier(uri, null, context.getPackageName())
val res : Drawable = context.getResources().getDrawable(imageResource)
I guess a dictionary look-up could work. ie. my_entry: “My entry”, and using the key (my_entry) as the R.id ?Ben Abramovitch
12/18/2019, 11:24 PMWill Nixon
12/18/2019, 11:26 PMBen Abramovitch
12/18/2019, 11:29 PMsealed class ResourceImages(@StringRes val name: Id, @DrawableRes val id: Int) {
object BlueSky : ResourceImages(R.string.blue_sky, R.drawable.image)
object RedSky : ResourceImages(R.string.red_sky, R.drawable.image)
}
Then you could just call the update method and go
textView.setText(resourceImage.name)
imageView.setImage(resourceImage.id)Will Nixon
12/18/2019, 11:37 PMBen Abramovitch
12/18/2019, 11:44 PMWill Nixon
12/18/2019, 11:45 PMBen Abramovitch
12/18/2019, 11:45 PMWill Nixon
12/18/2019, 11:46 PMpt
12/18/2019, 11:59 PMenum class Image(name: String, id: Int) {
BLUE_SKY("blue_sky", R.drawable.something)
}
Ben Abramovitch
12/19/2019, 12:01 AMWill Nixon
12/19/2019, 12:29 AMBen Abramovitch
12/19/2019, 12:33 AMpt
12/19/2019, 12:36 AMBen Abramovitch
12/19/2019, 12:38 AMpt
12/19/2019, 12:44 AMBen Abramovitch
12/19/2019, 12:45 AMWill Nixon
12/19/2019, 1:55 PM