Simple Calculator - Android



This is a simple Calculator with the basic addition, subtraction, multiplication and division operations.  

The functionality of the implemented application is more over similar to a basic calculator, where the user enters the first value following the desired operation and the second value and the equal key. 

The entering value will be displayed on the 'selector field' and once the operator is entered the value/result will be displayed in the 'result field'



Layout Design


  • Relative layout is used to design the above UI. 
  • A personalized AppBar is designed.
  • An imageView is used for the Codefest logo.
  • TextViews are used for the App Title, Selector Field and Result Field.
  • Buttons are used for the Number and Operations.

MainActivity.java 

Assign Variables to Match each Widget 



setViews() Method

Associate defined variables with their corresponding ids on the xml layout. 



computeOperations() Method

Performs the functions addition, subtraction, multiplication, division with a simple SWITCH case conditioning. 


onCreate() Method

Inside this method we set the content view of the layout and the personalized appbar, call the method setViews() and set onClickListeners for each button to capture the input from the user.





A Demo on how it works. 




Comments

  1. There is so much in this article that I would never have thought of on my own. Your content gives readers things to think about in an interesting way. 140 lbs to kg

    ReplyDelete

Post a Comment