Mobile Computing With Android ACST 4550 XML and the Android GUI
What is XML? eXtensible Markup Language Markup language for documents containing structured information Based on Standard Generalized Markup Language (SGML) Version 1.0 introduced by World Wide Web Consortium (W3C) in 1998 Bridge for data exchange on the Web
XML HTML XML to HTML Comparison Extensible set of tags Content orientated Standard Data infrastructure Allows multiple output forms Fixed set of tags Presentation oriented No data validation capabilities Single presentation
Authoring XML Elements An XML element is made up of a start tag, an end tag, and data in between. Example: <director> Matthew Dunn </director> Example of another element with the same value: <actor> Matthew Dunn </actor> XML tags are case-sensitive: <CITY> <City> <city> XML can abbreviate empty elements, for example: <married> </married> can be abbreviated to <married/>
Authoring XML Elements (cont’d) An attribute is a name-value pair separated by an equal sign (=). Example: <City ZIP=“94608”> Emeryville </City> Attributes are used to attach additional, secondary information to an element.
Authoring XML Documents A basic XML document is an XML element that can, but might not, include nested XML elements. Example: <books> <book isbn=“123”> <title> Second Chance </title> <author> Matthew Dunn </author> </book> </books>
XML Data Model: Example <BOOKS> <book id=“123” loc=“library”> <author>Hull</author> <title>California</title> <year> 1995 </year> </book> <article id=“555” ref=“123”> <author>Su</author> <title> Purdue</title> </article> </BOOKS> Purdue BOOKS 123 555 California Su title author article book year 1995 ref loc=“library” Hull
Apps – Android Manifest <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.helloandroid" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".HelloAndroid" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> @2011 Mihail L. Sichitiu
Apps – res (Resources) Folder anim drawable hdpi mdpi ldpi layout values arrays.xml colors.xml strings.xml xml raw
Apps – R.java Autogenerated, best if not manually edited gen/
Apps – View Hierarchy All the views in a window are arranged in a tree You show the tree by calling setContentView(rootNode) in the activity @2011 Mihail L. Sichitiu
Apps – Layout Defines how elements are positioned relative to each other (next to each other, under each other, in a table, grid, etc.) Can have a different layouts for each ViewGroup @2011 Mihail L. Sichitiu
Apps – Widgets All are View objects Examples: TextFields EditFields Buttons Checkboxes RadioButtons etc. @2011 Mihail L. Sichitiu
UI Events Usually handled by defining a Listener of the form On<something>Listener and register it with the View For example: OnClickListener() for handling clicks on Buttons or Lists OnTouchListener() for handling touches OnKeyListener() for handling key presses Alternatively, Override an existing callback if we implemented our own class extending View @2011 Mihail L. Sichitiu
Create the following Android App: SimpleCalculator Name your Activity: CalculatorActivity
You will create the following GUI: