Homework 2
Task 1 - Celsius-Fahrenheit converter ( 3 pt)
Create an application that converts user-entered Celsius values to Fahrenheit and vice versa. The app should also list the history of conversions made by the user.
- Use EditText to get user input ( setText() and getText() methods of EditText are helpful)
- There should be 2 buttons (1pt)
- "Convert" Button - clicking this will do the conversion and display the result in a TextView
- "Mode" Button - to switch between conversion modes (Celsius to Fahrenheit / Fahrenheit to Celsius).
- The button's text should reflect the active mode.
- There should be 1 TextView which displays the result when user clicks on "Convert" (1 pt)
- Use Formatted String Resources with arguments for this TextView
- Here the argument would be the numeric conversion result variable
- Use Formatted String Resources with arguments for this TextView
- After every conversion, the conversion should also be added to a "history" list. (1pt)
- Create this with a vertical LinearLayout.
- Every conversion should cause a new TextView with the details of the conversion (input value and unit, output value and unit) to be added to the top of the LinearLayout (in other words, newer conversions should appear on top).
- This can be controlled with an additional parameter of the addView() method
- Bonus task (1 pt), use a ScrollView, to get scroll behaviour if the no. of conversions in the history doesn't fit onto the screen
Tip: when acquiring the value from EditText, be mindful of the type it returns. You will have to do some type conversion before you can do calculations on it.
Other than above restrictions, feel free to be creative about the exact design of the UI. Images are only provided as a reference.
Task 2 - Observing lifecycle methods (2 pts)
Override the onPause, onResume, onStop, onDestroy methods as discussed in the lecture. Write some log statements in them and answer these questions:
- Which of the methods are called & in which order when:
- Changing device orientation
- Hitting the home button and returning to the application
- Hitting the back button and re-opening the application
- What happens to the EditText and TextView elements in each of these 3 cases (assuming the user has already performed one conversion).
Write your answers as a comment to the submission