EditText vs TextView

2019-04-03 04:52发布

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?

6条回答
The star\"
2楼-- · 2019-04-03 05:03

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.

The documentation pretty much sums it up:

EditText is a thin veneer over TextView that configures itself to be editable.

查看更多
地球回转人心会变
3楼-- · 2019-04-03 05:05

EditText is Input Type/Field for inputting text

TextView is TextField for showing text

查看更多
乱世女痞
4楼-- · 2019-04-03 05:06

TextView is just like Label tag of HTML on the other hand Edittext is input type.

Simple telling TextView is can't changable by the user. User only enter value.

查看更多
Animai°情兽
5楼-- · 2019-04-03 05:18

EditText is used for user input.

TextView is used to display text and is not editable by the user. TextView can be updated programatically at any time.

查看更多
Luminary・发光体
6楼-- · 2019-04-03 05:21

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.

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.

查看更多
Rolldiameter
7楼-- · 2019-04-03 05:23

EditText is used when you expect an input from the user. EditText provides the behavior for user input (display keyboard, paste, position indicator, etc).

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.

查看更多
登录 后发表回答