By entering numbers, the user can complete basic mathematical operations such as addition, subtraction, multiplication, and division. The user interacts with the application by performing the rudimentary task of pressing buttons on the keypad of the calculator. This android application requires user interaction to operate. Prabhu // Course: CS 855 // Date: 28/010/2019 // Assignment 2 /* Description: This program helps to perform the operations and the calculations of the basic calculator*/ //- package import import android.os.Bundle import .activity_main.* import class MainActivity : AppCompatActivity() Program: main_activity.kt // Author: Tanu. In my case, the package name is, it might vary in your case. The main_activity.kt can be found in:Īpp → java → →MainActivity.kt The code is pretty much self-explanatory. Then in the Equals function, I am using the Expression Builder library and calling its method Expression Builder to do the calculations. To do this, I have created a function called evaluateExpression() which does the appending job to the text view. Step 6: Actual Kotlin coding for the calculatorįirst, I’m appending 1, 2, 3,….0 when the users press the keys to the text view, respectively. It is a mechanical process because of multiple text views. I’m placing all the text view inside a linear layout. Here we can use the text view layout rather than buttons for the keys. This is the main layout file here you need not use the UI editor, rather you can code the entire layout using XML. Step 4: Configuring the “activity_main.xml” file A style can be applied to an individual View (from within a layout file) or to an entire Activity or application (from within the manifest file).Īpp →res →values →styles.xml 0dp match_parent 1 21sp center 0.5dp 0dp match_parent 1 21sp center 0.5dp 0dp match_parent 1 21sp center 0.5dp 0dp match_parent 1 21sp center 0.5dp Īll the above are just style properties for the calculator defined in the styles.xml file. The style file is used to define the format or the look for a UI.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |