カテゴリー:
睡眠導入
閲覧数:326 配信日:2018-04-26 10:15
activity_main.xml を編集
android:id="@+id/textview1"を追加
▼activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
kotlin-stdlib-jre7 is deprecated. Please use kotlin-stdlib-jdk7 instead
Unresolved reference: textview
解決方法
案A.「MainActivity.kt」に「import kotlinx.android.synthetic.main.activity_main.*」を追加
▼MainActivity.kt
import android.widget.TextView
import kotlinx.android.synthetic.main.activity_main.*
案B.従来の手法で記述
▼MainActivity.kt
//textview.text = greeting //追加
findViewById<TextView>(R.id.textview).text = greeting
案A.「MainActivity.kt」に「import kotlinx.android.synthetic.main.activity_main.*」を追加
▼work/w4c/android0/introducesleep20180426/MainActivity.kt
package work.w4c.android0.introducesleep20180426
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var greeting = "こんにちは" //追加
textview.text = greeting //追加
//findViewById<TextView>(R.id.textview).text = greeting
}
}
案B.従来の手法で記述
▼work/w4c/android0/introducesleep20180426/MainActivity.kt
package work.w4c.android0.introducesleep20180426
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
//import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var greeting = "こんにちは" //追加
//textview.text = greeting //追加
findViewById<TextView>(R.id.textview).text = greeting
}
}
・Unresolved reference: textview