After upgrading to compile SDK
version 26, all findViewById
showing error:
not enough information to infer parameter T in fun findViewById(id: Int): T!
This is because as of Android O, we don't need to cast it. There are a few options. Replace:
val textInput = findViewById(R.id.edit_text) as TextInputLayout
With either:
val textInput:TextInputLayout = findViewById(R.id.edit_text)
Or:
val textInput = findViewById<TextInputLayout>(R.id.edit_text)
If you want to know what happened under the covers, as of O underlying method changed to
public <T extends View> T findViewById(@IdRes int id) {
return this.getDelegate().findViewById(id);
}
In pure Java you will have for example
TextView textView = findViewById(R.id.textview1);
In Kotlin you can go with this
val textView = findViewById<TextView>(R.id.textview1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With