44139 – Mobile Computing@UA
17623 - Software Engineering in Mobile Computing@CMU
2010/2011
In-class #2 – Layouts and Controls
Objectives:
• Understanding layouts, controls and activities
• Deploy a simple Android application
• Understand and implement ListView with multiple events
Material:
• Class presentations
• Eclipse IDE with Android ADT
Background
- Please refer to the InClass presentations on
o “Dissecting Android Apps”
o “Android Components”
o “Android App Lifecycle”
o “Android Layout, Controls and Activities”
More details can be seen in http://elearning.ua.pt
Exercise: ListView Example
In Android, ListView is a control that is used to show a list of items in a vertically scrolling list. For example, in a
shopping list this control will have a set of items displayed for you in a vertical orientation. We can use Listview to
display the list of items.
In this example, we will have a list of selectable items.
Go to Eclipse and create a new project named “ListViewExample”.
Your res/main.xml file should look like this:
[jfernan, jcunha]@ua.pt 1/3
44139 – Mobile Computing@UA
In-class #2 – Layouts and Controls
And your src/.java file should look like this:
Notice the ListView declaration and its use as “lv1”.
The result should be something like this:
[jfernan, jcunha]@ua.pt 2/3
44139 – Mobile Computing@UA
In-class #2 – Layouts and Controls
Exercise: ListView with multiple choice
Let’s now make a more “fancy” ListView, where you can select multiple items of the list and have a nice icon to
denote their selection.
Go to Eclipse and create a new project named “ListMchoice”.
Your res/layout/main.xml file should look like this
Then, go to your src/.java file and add the following code:
Notice the differences from the previous example… the key is in the “setChoiceMode ()” method.
The result should look like this:
More details and other evolutions of this example to really “fancy” ListView apps can be found at:
http://www.androidpeople.com/tag/listview/
[jfernan, jcunha]@ua.pt 3/3