如何在 EditText 中设置文本 [英] How To Set Text In An EditText
本文介绍了如何在 EditText 中设置文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何设置 EditText 的文本?
How can I set the text of an EditText?
推荐答案
如果您查看文档中的 EditText
,你会发现一个 setText()
方法.它接受一个 String
和一个 TextView.BufferType
.例如:
If you check the docs for EditText
, you'll find a setText()
method. It takes in a String
and a TextView.BufferType
. For example:
EditText editText = (EditText)findViewById(R.id.edit_text);
editText.setText("This sets the text.", TextView.BufferType.EDITABLE);
它还继承了 TextView
的 setText(CharSequence)
和 setText(int)
方法,所以你可以像常规一样设置它TextView
:
It also inherits TextView
's setText(CharSequence)
and setText(int)
methods, so you can set it just like a regular TextView
:
editText.setText("Hello world!");
editText.setText(R.string.hello_world);
这篇关于如何在 EditText 中设置文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文