I need to pass a resource ID to a method in one of my classes. It needs to use both the id that the reference points to and also it needs the string. How should I best achie
The Kotlin approach
inline fun > T.getId(resourceName: String): Int { return try { val idField = getDeclaredField (resourceName) idField.getInt(idField) } catch (e:Exception) { e.printStackTrace() -1 } }
Usage:
val resId = R.drawable::class.java.getId("icon")