Last active
December 1, 2017 11:42
-
-
Save kubode/f0f81c7224fc7904e111c975f7161217 to your computer and use it in GitHub Desktop.
AndroidOのfindViewByIdの仕様変更 ref: https://qiita.com/kubode/items/c7fe9c091fdf5533d36b
This file contains 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
// こっちだとTextView!!になるので | |
val text26_1 = findViewById<TextView>(android.R.id.text2) | |
// 型を明示するほうが良さそう | |
val text26_2: TextView = findViewById(android.R.id.text2) |
This file contains 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
// compileSdkVersion 25 | |
@Suppress("UNCHECKED_CAST") | |
fun <V : View?> Activity.find(@IdRes id: Int): V = findViewById(id) as V | |
// compileSdkVersion 26 | |
fun <V : View?> Activity.find(@IdRes id: Int): V = findViewById<V>(id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment