‫Welcome back.
‫In this video we'll add the functionality for this application.
‫We need to convert the entered USD amount by the user in this edit text and display the result of conversion
‫in this text view.
‫For that, I need to handle the click events on the convert button dot set on Click listener, and here
‫I'll replace it with curly braces.
‫In order to pass a Lambda expression set on click listener is a function used to assign a click event
‫listener to a view, such as a button or any other clickable UI element.
‫The set on click listener function takes a lambda expression as an argument, and you can use the curly
‫braces syntax to define the behavior that should occur when the view is clicked.
‫I need to get the USD amount from this edit text.
‫For that I need to create a var entered USD equals.
‫To edit text dot text dot two string.
‫There is a very important note here.
‫Whenever you want to get an edit text input text, we need to store it inside a string variable.
‫This is of type string, but the entered text is of type number.
‫We need to store it inside a number.
‫For that I need to create var entered USD double.
‫It's of type double equals to enter USD, which is a string dot two double method.
‫In Kotlin, you can convert a string to a double using two double function, which is a built in function
‫for strings.
‫So I use two double to convert.
‫This entered USD which is of type string and store it inside double variable called entered USD.
‫But it is double and to be professional, we need to create everything in a clean structure for that
‫I create outside this Oncreate function.
‫Another function called make conversion.
‫Start with fun, make conversion and this function takes into the parameter USD.
‫It's of type double and returns a double double and open this curly braces.
‫Then I need to return a double.
‫Also you can create a var of type double euros USD times 0.94.
‫This is the rate the current rate of conversion from USD to euros and then we need to return euros.
‫Moreover, you can skip this creation of this variable and you can return USD times 0.94.
‫You can use both ways.
‫Let's move up.
‫And here I need to call this function make conversion.
‫And I need to pass the entered USD double variable.
‫I'll pass the USD the dollars.
‫I multiply it with 0.94 and return the euros.
‫This function make conversion returns a double.
‫So I'll make use of this function and it's returning type.
‫And I'll create var euros equals to make conversion.
‫This returns a double and this variable is of type double.
‫Then I need to display the conversion result text view result text view dot set text.
‫Or I can use the property name which is the text.
‫So result text view dot text equals to.
‫This is the assigning.
‫So I'm using set text I'm using the setter of this text view euros dot two string I need to convert
‫this double into a string in order to display it in the text view.
‫Let me save and run this application.
‫Select your emulator and click run.
‫And this is our amazing application.
‫Enter USD and you can see the keyboard is only numbers.
‫I'll enter $1,010 and you can see the text is in black.
‫I need to change this text into white.
‫So convert to euros and it's €9.3999.
‫And this is correct.
‫I need to display euros here.
‫Euro keyword.
‫And to change the color of the entered text in the edit text, let us go to the code edit text and here
‫I need to change the color text color into white.
‫Also, I need to add here the text dot to string plus euro.
‫Let me run again.
‫Also you can convert it to string template Alt+ enter to convert the.
‫A string concatenation.
‫And here we go enter USD.
‫I'll enter ten.
‫You can see it's in white.
‫Convert to euros and €9.3999.
‫Congratulations guys!
‫We created this amazing app that convert dollars into euros.