Kotlin Android TextView and EditText
Android TextView is a user interface which displays the text to the user.
A simple XML code of TextView in a layout is shown below.
We can get and modify the content of text view defined in the XML layout in Kotlin class file as:
The EditText is a user interface which is used for entering and changing the text. While using edit text in XML layout, we must specify its inputType attribute which configures the keyboard according to input type mention.
The simple XML code of EditText in a layout is shown below.
We can get and modify the content of edit text defined in the XML layout in Kotlin class file as:
Kotlin Android TextView and ExitText Example
In this example, we input the text value in ExitText and display its value in the TextView on clicking the Button.
We are also watching the changes made over EditText using addTextChangedListener () method and TextWatcher interface.
In the activity_main.xml file add the following code.
Add the following code in MainActivity.kt class. In this class, we are getting the value of the edit text and display it in text view by clicking the button. At the same time, we are also watching the changes made over EditText using addTextChangedListener () method and TextWatcher interface. To learn more about TextWatcher refers to https://www.javatpoint.com/android-edittext-with-textwatcher