This is a mirror of official site: http://jasper-net.blogspot.com/

Working with Android Layouts and ListViews

| Tuesday, February 15, 2011
I've been the owner of an Android phone for about 5 months now. The thought of creating an application for the Android platform has appealed to me ever since. That's why I recently started with Android development as a learning project for the next couple of weeks. In this post I will start sharing my experience with developing Android applications.

Getting started
The basic thing, while starting out with a new technology, is getting to know the fundamentals. There are some great introduction and advanced videos by Google on how to develop applications for the Android platform. The use of proper tooling can also help out a lot on this part. Both Eclipse and IntelliJ has great support for developing Android application since IntelliJ 10 (and it's free to use).

For this project I'm trying to create a native Android client based on the Hippo GoGreen mobile website. If you take a look at the mobile site, there are two main entry points for browsing the site: Products and Events. I started out with Events, where I wanted to create a list of event items and show the event with a nice calendar item on the left next to the title of the event. I wanted the end result to look something like:

listitems.png

In Android you can create a screen/page by creating an Activity. Adding a ListView to an Activity is a matter of configuration. With Android you can define the layout of your View either by defining a piece of XML, or by writing the code in Java. For this example I use the XML notation.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">
   <ListView
       android:id="@android:id/list"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent" />
   <TextView
       android:id="@android:id/empty"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:text="@string/empty_events"
       android:gravity="center"
       android:textAppearance="?android:attr/textAppearanceMedium" />
</FrameLayout>

Read more: Jeroen Reijn

Posted via email from Jasper-net

0 comments: