Android 编辑文本与文本视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23531599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
EditText vs TextView
提问by user2927724
I read the API's and see that TextView
is a super class to EditText
, but I have a short and simple question: Generally speaking, EditText
is used when the text displayed is subject to change, whether it's from the user or the app. TextView
is used when the text displayed is to be constant/same forever. Is this correct?
我阅读了 API 并看到它TextView
是 to 的超类EditText
,但我有一个简短而简单的问题:一般来说,EditText
当显示的文本可能会发生变化时使用,无论是来自用户还是应用程序。TextView
当显示的文本永远保持不变/相同时使用。这样对吗?
采纳答案by SMK
If you have done any java projects before, I see Textview
and EditText
are just same as JLabel
and JtextField
. If you want to ask user to enter username you will set an TextView with ("username " text in that, like you would do the same for JLabel). And then you make a textbox appear for user to enter the username that textbox is EditText
. EditText is where user give their inputs for the program.
如果你以前做过任何Java项目中,我看到的Textview
和EditText
都只是同JLabel
和JtextField
。如果你想要求用户输入用户名,你将设置一个 TextView (其中的“用户名”文本,就像你对 JLabel 做的一样)。然后你让一个文本框出现,让用户输入文本框的用户名EditText
。EditText 是用户为程序提供输入的地方。
User cannot change something in TextView but program can(After user input correct user name you can set text for another TextView by the program saying that "Details correct" if you want that you have to write it in your program code. User can't make it appear). User can input any user name, But "username" textfield or TextView
will remain unchange as "username" just like in a normal login interface.
用户不能更改 TextView 中的某些内容,但程序可以(在用户输入正确的用户名后,您可以通过程序为另一个 TextView 设置文本,如果您希望必须在程序代码中编写“详细信息”,则用户不能让它出现)。用户可以输入任何用户名,但“用户名”文本字段或TextView
将保持不变为“用户名”,就像在正常登录界面中一样。
回答by Garret
EditText is used for user input.
EditText 用于用户输入。
TextView is used to display text and is not editable by the user. TextView can be updated programatically at any time.
TextView 用于显示文本,用户不可编辑。TextView 可以随时以编程方式更新。
回答by ajacian81
The names of them are pretty self explanatory. TextView is the widget used when you want the user to View the Text (such as a label, etc) and EditText used when you want the user to be able to edit the text. The text in either widget can be set programmatically or via xml using the android:text
parameter.
他们的名字是不言自明的。TextView 是您希望用户查看文本(例如标签等)时使用的小部件,当您希望用户能够编辑文本时使用 EditText。可以使用android:text
参数以编程方式或通过 xml 设置任一小部件中的文本。
The documentationpretty much sums it up:
该文件几乎总结起来:
EditText is a thin veneer over TextView that configures itself to be editable.
EditText is a thin veneer over TextView that configures itself to be editable.
回答by Eduardo Bonet
EditText is used when you expect an input from the user. EditText provides the behavior for user input (display keyboard, paste, position indicator, etc).
当您期望来自用户的输入时使用 EditText。EditText 提供用户输入的行为(显示键盘、粘贴、位置指示器等)。
If your app is changing the content to display, you can just reset the text for the TextView. The user however cannot mess with it.
如果您的应用正在更改要显示的内容,您只需重置 TextView 的文本即可。然而,用户不能弄乱它。
回答by Giorgi Tsiklauri
EditTextis Input Type/Field for inputting text
EditText是用于输入文本的输入类型/字段
TextViewis TextField for showing text
TextView是用于显示文本的 TextField
回答by Ssingh
TextView is just like Label tag of HTML on the other hand Edittext is input type.
TextView 就像 HTML 的 Label 标签,另一方面 Edittext 是输入类型。
Simple telling TextView is can't changable by the user. User only enter value.
用户无法更改简单的 TextView。用户只输入值。