在EditText Kotlin中设置文本 [英] Setting text in EditText Kotlin

查看:200
本文介绍了在EditText Kotlin中设置文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在EditText中设置文本,但是它说:

I am trying to set text in a EditText but it says:

Type mismatch. 
Required: Editable 
Found: String

我的代码如下:

String name = "Paramjeet"
val nametxt = findViewById (R.id.nametxt) as EditText
nametxt.text = name

不要说使用setText,因为我使用的是Kotlin,而不是Java.

Don't say to use setText because I am using kotlin, not Java.

推荐答案

使用setText(String),因为editText.text期望的是Editable,而不是String.

Use setText(String), since editText.text expects an Editable, not a String.

这篇关于在EditText Kotlin中设置文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆