我的布局中有这个TextView
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="text"/>
现在,我想使用Kotlin Android Extension设置此Textview的文本。因此,我在apply plugin: 'kotlin-android-extensions'
文件中添加了build.gradle
。
现在在我的课堂上,我想使用
textView.text("MyText")
如果我使用自动完成功能“ alt + return”导入textView,则该导入不是合成导入,而是直接导入资源com.package.R.id.textView
最后,我有一个整数对象而不是TextView
有人可以向我解释我在做什么错吗?
答案 0 :(得分:0)
在textview中使用textView.setText(“”)代替textView.text(“”),例如-
textView.setText(“此处输入文字”);
答案 1 :(得分:0)
好像您导入了错误的程序包,只是删除了程序包com.package.R.id.textView
而不是这个
您需要import kotlinx.android.synthetic.main.your_layout_file_name.*
答案 2 :(得分:0)
首先导入此 导入kotlinx.android.synthetic.main.layoutfile。*;
然后调用textview并分配settext(不要使用alt + enter)