How to make an interface for currency converter app?

So all right so now let’s let’s uh head over so now we have to head over to our code so let’s head over to our core and now um actually before that we have to introduce a new concept let me connect the charger all right this is a new concept that we’re going to learn now is that every view on your layout has something called id so you know you click on all the views here you notice this id in the attributes pane id id it is something unique so id is like your social security number each one has a unique social security number or like a driving license number a unique driving license number so uh whenever you want to identify a person right you can use your social security number and you can be sure that there’s no other person that has the same number so we must add a unique id to each of these views and we’ll go over why are we doing that first let us add a unique id now edit text there’s something we have to note here is the convention of adding an id.

So always it’s all small letters and only underscore spaces so the convention says the first two letters would be the first two letters of your widget name so edit text so e t first two letters so i i know this is big enough let me increase the text font size and if you if it asks this click yes so let us increase the font size 80 maybe too much or maybe five so it must be a little more clear for all of you know so the first two letters is the first three letters of your widget then underscore then you type what is that widget meant for it is meant for the value so et unesco value now for this textview textview t v so t b underscore what’s it meant for it’s meant for showing the value if you underscore value this one and click yes if it asks you this one this is a text view tv underscore what’s it doing it’s showing a label it’s it’s not going to change ever so you don’t need an id for this but let’s just give it label.

Now i will do this this button and hopefully you can get the pattern and do these two as a challenge so for the first one button now the button for the code for button is not b but it’s actually btn the btn underscore now we’ll write the the it is meant for canadian dollar so as a challenge if you want to use the same thing so think about what id will you give for these two and i will do it and if you want you can do it uh you can see this video as a solution so let’s do btn and it’s called inr right it shows indian rupees click on yes for euro btn underscore eu are you know and okay didn’t give anything so no reflection yes now you notice each thing each of these views have a unique id none of them are equal and they’re following the convention of what an id should be now why are we doing this let us see in our code what we want to do is we want to like access these views in our layout so first let us create a variables global variables so within our main activity class let us create global variables for each of the views that will change or that we want to access so currently we want to only access this one this one this to get the amount.

The user entered this one to display the converted amount this one to check like if the user taps this button to check if the user taps this button checking the user taps this button so we only are concerned with these five one two three four five this is a label so we don’t really it’ll always stay static so we don’t really need to think about that too much so head over to your java and create a variable for each of those views so our first one is edit text so and if it if they ask you to import if it’s red alt enter and import that so each of the widgets here in our xml they have a class that’s defined by android so edittext has this edittext class you can hold ctrl and hover over it you see this class edittext so it has a class now the convention for naming variables in java global variables in java is in android is m that says member variable then almost the same convention as your id so camel case first of all first two letters that’s the first two letters of this m80 and then value very similar next is text view.

So we made one for this one let’s create one for this one now so m tv value now for these three buttons so i will do the first button and you can you can create these two as a challenge try to see if you’re if you’re getting this so let’s limit to the first one button m the three letter or the short code for button is btn and what’s this button for c8d so we’re creating variables of this button type so can you create two more variables for i and r and e u r so you can give it a try and you can look at this as a solution i n r and m right actually button so if i’m going to pass let me type in button there’s only one chain click this one m btm e u r and c now you have these five variables very nice now the thing is they aren’t equated to any value you haven’t assigned any value to these variables now that’s when in this oncreate method you will uh write that code for that so you initialize these variables let’s initialize the first one to something what is that something basically you want to equate this met value variable this view here how will you do it that brings us to this amazing method defined by android called find view by id so let us implement that go back to java type in here find view by id now within it type in it.

It expects an id here so you can type in r dot id dot now type the same id of this view which is et underscore value so always start with r dot id which is the resources dot ids so r dot id uh et and score value so this powerful method what it does is it looks in your xml file for a view with this id it searches this etm score value is it equal to vtn value yes so it stops and then it it returns the view that it found it it returns this view to this variable so it finds the view with this id in your xml layout and it equates it to this java variable let’s do it for this for all the five so you can do this a challenge now so um so you can try to figure out what’s the pattern here so for the second variable is equal to find v by id r dot id always r dot id dot now here you can write pv until value which is this view so what it does android search is okay find viewer id tv underscore value is this tv and so value no is this dbs valueHow to

Leave a Comment