editText获取文本kotlin [英] editText get text kotlin

查看:1039
本文介绍了editText获取文本kotlin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在kotlin中获取editText并与吐司一起显示.

How to get editText in kotlin and display with toast.

var editTextHello = findViewById(R.id.editTextHello)

我尝试过但是显示对象

Toast.makeText(this,editTextHello.toString(),Toast.LENGTH_SHORT).show()

推荐答案

您缺少从findViewByIdEditTextView的转换:

var editTextHello = findViewById(R.id.editTextHello) as EditText

然后,您想在烤面包中显示EditTexttext属性:

Then, you want to display the text property of the EditText in your toast:

Toast.makeText(this, editTextHello.text, Toast.LENGTH_SHORT).show()


作为记录,这只是更惯用的Kotlin,等效于在EditText上调用getText(),就像您在Java中那样:


For the record, this is just the more idiomatic Kotlin equivalent to calling getText() on your EditText, like you'd do it in Java:

Toast.makeText(this, editTextHello.getText(), Toast.LENGTH_SHORT).show()

这篇关于editText获取文本kotlin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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