Skip to content

Instantly share code, notes, and snippets.

@hhaappy163
Created April 25, 2023 09:05
Show Gist options
  • Select an option

  • Save hhaappy163/2df59c0838aaa6f9fffa6944d3710a4b to your computer and use it in GitHub Desktop.

Select an option

Save hhaappy163/2df59c0838aaa6f9fffa6944d3710a4b to your computer and use it in GitHub Desktop.
viewbinding快速填充数据
fun ViewBinding.invoke(any: Any){
any.javaClass.apply {
declaredFields.forEach {
kotlin.runCatching {
it.isAccessible = true
val value = it[any].toString()
val view = this@invoke.javaClass.getDeclaredField(it.name).get(this@invoke)
when(view){
is TextView -> view.text = value
is ImageView -> view.load(value)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment