Skip to content

Instantly share code, notes, and snippets.

@kubode
Last active December 1, 2017 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubode/f0f81c7224fc7904e111c975f7161217 to your computer and use it in GitHub Desktop.
Save kubode/f0f81c7224fc7904e111c975f7161217 to your computer and use it in GitHub Desktop.
AndroidOのfindViewByIdの仕様変更 ref: https://qiita.com/kubode/items/c7fe9c091fdf5533d36b
// こっちだとTextView!!になるので
val text26_1 = findViewById<TextView>(android.R.id.text2)
// 型を明示するほうが良さそう
val text26_2: TextView = findViewById(android.R.id.text2)
// 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