Issue
I'm new to Android & Kotlin development.
I wanted to get started with a simple "Hello World", but am already running into problems.
I added a Textview to my MainActivity and want to set an onClick listener to change the text of a TextView I dragged into the activity.
The compiler is now complaining that 'TextView' is an unresolved reference (it does the same with Buttons etc.).
I then added a kotlinx import as suggested by a website, but this fails to solve anything. Code sample below, anything with an asterisk as a line comment was added by me.
package com.example.my.mynewapp
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.fragmentX.view.* // *
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val textView: TextView = findViewById(R.id.testView) as TextView // *
textView.setOnClickListener { // *
textView.text = "You clicked me! You flipping clicked me!" // *
} // *
}
}
Would anyone have any idea what's going on?
Solution
It should have been automatically imported, but there should be
import android.widget.<WhateverIsMissing>
Replace WhateverIsMissing with the reference that is unresolved
Answered By - frogstair
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.