Created
April 25, 2023 09:05
-
-
Save hhaappy163/2df59c0838aaa6f9fffa6944d3710a4b to your computer and use it in GitHub Desktop.
viewbinding快速填充数据
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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