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?
问题:
回答1:
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.
回答2:
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.
回答3:
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.
回答4:
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.
回答5:
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.
回答6:
EditText is Input Type/Field for inputting text
TextView is TextField for showing text