Reputation:
I created a TextView inside activity_main.xml and specified an ID for it, but when I go into MainActivity and click on that ID, it does not recognize TextView, and what does the red line under everything look like? How should I solve this problem?
Upvotes: 0
Views: 1655
Reputation: 1
As indicated in one of the posts above (for kotlin) I converted a project from java code to kotlin and had to manually add the line
apply plugin: 'kotlin-android-extensions'
to my gradle file example:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
Edit note: I get the complier message The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin.
So evidently, Google is heading in a "view-binding" direction
Upvotes: 0
Reputation: 138
At gradle app
plugins {
id 'kotlin-android-extensions'
}
or
apply plugin: 'kotlin-android-extensions'
then your Activity Import this
import kotlinx.android.synthetic.main.activity_main.*
Upvotes: 1
Reputation: 16
The mainActivity does not know where the txt_test is coming from so you have to give it the reference. I would recommend either use ViewBinding or use the old:
val txt = findViewById(R.id.the_id_of_your_textView)
Upvotes: 0