Part 2: Setting up the xml
Hello there continuing from where we left ie, activity_main.xml
copy the below code in between the xml file where linear layout has been defined
after this xml part is done. (dont worry will come to explaining the code shortly )
Moving on to strings.xml located at res>values>strings.xml
here the name is the variable we used in xml to reference the string defined in value. It is done so that if we need to change the variable we may change the value from here only and the value will be changed from complete application (off course where we have defined the variable)
for example: name app_name is defined with value my first app, this means if we want to change the name of our app all we need to do is change the value here and name will be changed from every where wher variable app_name is used.
to make attributes click on add > select String> enter the values for name& value, and you are done.
here we have used values as below
EXPLAINING THE CODE
So the section where we understand what everything we just did, comes here :)
<TextView //defining the text area and the text to be displayed android:layout_width="fill_parent" //defines the width of text area
android:layout_height="wrap_content"// defines the height of text area
android:text="@string/head" // this is where the variable head is defined which has value in strings.xml
android:textSize="45sp" //defines the size of text
android:layout_gravity="center" // defines the layout alignment
android:gravity="center" //defines the text alignment
android:id="@+id/tvDisplay" // defines the id. it will be used later in funcionality
/> // closing the textview tag
After this we defined the two buttons one for add other for subtract, the attributes we used in them too are similar and differ in id, and text. and ofcourse we used button tag for buttons<Button></Button>
So this was all for today after completing till here we will be having output that may look like this
for any query or suggestions comment or share .
No comments:
Post a Comment