COEN268-Exercise2 - Exercise#2 Android Application Development Temperature converter Create a temperature converter In this lab you learn how to create

COEN268-Exercise2 - Exercise#2 Android Application...

This preview shows page 1 - 5 out of 12 pages.

Exercise #2 Android Application Development Temperature converter Create a temperature converter In this lab you learn how to create and consume Android resources and create an interactive application. 1. Create Project Create a new Android project with the following data. Property Value Application Name Temperature Converter Package name edu.scu.android.temperature API (Minimum, Target, Compile with) Latest Template Empty Activity Activity MainActivity Layout activity_main 2. Create attributes Android allows you to create static resources to define attributes, e.g., Strings or colors. These attributes can be used in other XML files or by Java source code. Select the res/values/strings.xmlfile to open the editor for this file. Ensure that the file looks like You want to add a Colordefinition to the file. Press the Add button for this.
Image of page 1
Select the Color entry in the following dialog and press the OK button. Enter myColor as the name and #F5F5F5 as the value.
Image of page 2
Add more attributes, this time of the String type. String attributes allow the developer to translate the application at a later point. Name Value celsius to Celsius fahrenheit to Fahrenheit calc Calculate Switch to the XML representation and validate that the values are correct. <?xml version="1.0" encoding="utf-8"?> <resources> <string name = "app_name" > Temperature Converter </string> <string name = "action_settings" > Settings </string> <string name = "hello_world" > Hello world! </string> <color name = "myColor" > #F5F5F5 </color> <string name = "celsius" > to Celsius </string> <string name = "fahrenheit" > to Fahrenheit </string> <string name = "calc" > Calculate </string> </resources> 3. Using the layout editor Select the res/layout/activity_main.xmlfile. Open the associated Android editor via a double-click on the file. This editor allows you to create the layout via drag and drop or via the XML source code. You can switch between both representations via the tabs at the bottom of the editor. For changing the position and grouping elements you can use the Eclipse Outline view. The following shows a screenshot of the Palette side of this editor. This element allows you to drag and drop new Viewelements into your layout. To identify the Viewelements easier, you can switch the representation to show the icon and the text as depicted in the following screenshot.
Image of page 3
Note The Palette view changes frequently so your view might be a bit different. 4. Add views to your layout file In this part of the exercise you create the base user interface for your application. Right-click on the existing Hello World! text object in the layout. Select Delete from the popup menu to remove the text object. Afterwards select the Text Fields section in the Palette and locate the Plain Text (via the tooltip). Click on the Text Fields section header to see all text fields. Drag the Plain Text widget onto your layout to create a text input field.
Image of page 4
Image of page 5

You've reached the end of your free preview.

Want to read all 12 pages?

  • Fall '12
  • JoshuaO'Connor
  • Widgets, Radio button, new android project, Android Application Development

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture