Homework 2
Task 1 - Celsius-Fahrenheit converter
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)
- 1 to apply the conversion, clicking this will display the result in a TextView
- another 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 to display the last conversion result (1 pt)
- Use a larger fontsize than the default
- After every conversion, the conversion should 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, mode, output) 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 (no points), try wrapping the LinearLayout inside a ScrollView, to get scroll behaviour if the no. of conversions in the history doesn't fit onto the screen
- Set fillViewport of ScrollView to true
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)
This task involves conducting some experiments of different situations and observing how the Android lifecycle Override the onCreate, onDestroy, onStart, onStop, onPause, onResume methods as discussed in the lecture. Write some log statement in each of them and answer these questions:
- Which of the lifecycle methods are called & in which order when:
- Changing device orientation (make sure your device orientation isn't in the locked setting)
- Hitting the home (circle) button and returning to the application
- Hitting the back button and re-opening the application
- The starting point for each above case should be:
- User has previously already done at least 1 conversion, plus something new has been written into the EditText and "Convert" has not yet been clicked.
- Answer: What happens to the EditText and TextView elements, their displayed values in each of these 3 cases?
- Write your answers as a comment to the submission