<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Android-Dev on despatches</title><link>https://icle.es/tags/android-dev/</link><description>Recent content in Android-Dev on despatches</description><generator>Hugo</generator><language>en</language><lastBuildDate>Fri, 20 Jun 2025 09:25:00 +0100</lastBuildDate><atom:link href="https://icle.es/tags/android-dev/index.xml" rel="self" type="application/rss+xml"/><item><title>First Love</title><link>https://icle.es/2011/06/08/first-love/</link><pubDate>Wed, 08 Jun 2011 00:13:25 +0000</pubDate><guid>https://icle.es/2011/06/08/first-love/</guid><description>&lt;p>The first phone I ever got was a Motorola Startac 70. This was back in 98 or so,
a flip phone and I still remember it ever so clearly!&lt;/p>
&lt;p>I&amp;rsquo;m pretty sure my next phone was an A1000, a pretty awesome phone. This was
around the time that Motorola started releasing the razr which I was far from
impressed with. I jumped ship to Sony Erricson and I went through a couple of
those before heading over to the wonderful world of HTC. I wanted a smart phone
to help with work and so on and I got the HTC HD (If I recall) which was a
Windows phone.&lt;/p>
&lt;p>While this make me uncomfortable, I was still more comfortable with this than a
blackberry. I couldn&amp;rsquo;t get an iPhone for some reason that I cannot remember.&lt;/p>
&lt;p>The phone was pretty laggy and I got pretty sick of it pretty quick. I then got
myself my first android phone - an HTC Hero&amp;hellip; Most people didn&amp;rsquo;t like the curvy
bit at the bottom but I didn&amp;rsquo;t care. I was happy to be on the cutting edge. It
was also a bit slow and laggy. but it was android and I loved it. It started a
brand new love affair&amp;hellip; Let me tell you more&amp;hellip;&lt;/p></description><content:encoded><![CDATA[<p>The first phone I ever got was a Motorola Startac 70. This was back in 98 or so,
a flip phone and I still remember it ever so clearly!</p>
<p>I&rsquo;m pretty sure my next phone was an A1000, a pretty awesome phone. This was
around the time that Motorola started releasing the razr which I was far from
impressed with. I jumped ship to Sony Erricson and I went through a couple of
those before heading over to the wonderful world of HTC. I wanted a smart phone
to help with work and so on and I got the HTC HD (If I recall) which was a
Windows phone.</p>
<p>While this make me uncomfortable, I was still more comfortable with this than a
blackberry. I couldn&rsquo;t get an iPhone for some reason that I cannot remember.</p>
<p>The phone was pretty laggy and I got pretty sick of it pretty quick. I then got
myself my first android phone - an HTC Hero&hellip; Most people didn&rsquo;t like the curvy
bit at the bottom but I didn&rsquo;t care. I was happy to be on the cutting edge. It
was also a bit slow and laggy. but it was android and I loved it. It started a
brand new love affair&hellip; Let me tell you more&hellip;</p>
<p>This phone got rooted and got all forms on interesting things installed on
there. I eventually wanted a phone that was faster and more responsive and opted
for the HTC Desire.</p>
<p>Another phone that I loved and it was quicker&hellip; and that was nice. I finally
had a phone that could compete with the iPhone and did a lot of the things that
I wanted it to do. It provided me with the level of flexibility that I wanted.</p>
<p>Unsurprisingly, I rooted that one too and loved it. I wanted the HTC Desire HD
when it came out but I had to wait out contract expiries and a good thing it was
too.</p>
<p>By the time I was able to get a new phone, I was sick of HTC for various
reasons. I had installed a ROM on my phone without HTC Sense and I was surprised
at just how much I just did not miss it.</p>
<p>On doing some research, I also realised that HTC had fallen behind and had no
&ldquo;superphones&rdquo; available.</p>
<p>This led me to the Samsung Galaxy S2 and the Motorola Atrix. It was a tough call
for me and for a while, I was seriously considering the S2.</p>
<p>Throwing the question around the office, the Atrix was recommended and without a
second thought as such, I went for it. Motorola deserved another shot and I
loved their high resolution screens.</p>
<p>My mum got the S2 and someone else I know had it too. I had gotten used to other
people having the same phone as me with the Desire, but I love to have something
different. The S2 seemed a little flimsy and I like the more solid feeling from
the Atrix.</p>
<p>The phone arrived today along with a keyboard, mouse, remote control and a dock.
I had a very busy day, so didn&rsquo;t really have a change to play around with the
accessories. I&rsquo;ll tell you what though - I remember why I loved Motorola in the
first place.</p>
<p>I feel sophisticated and techy with the phone. I love the fingerprint scanner.
Its a little laggy and its arguable as to whether its any quicker than punching
in the passcode but that&rsquo;s not relevant. Its bloody cool.</p>
<p>And the screen - the screen in absolutely beautiful. Better than HD.</p>
<p>It also come jam packed with some cool applications like Swype. I used to have
it a long time ago when it could be purchased.</p>
<p>After it was pulled, I switched to SlideIT which I thoroughly enjoyed. Going to
back to Swype though has been beautiful. It just looks and feels much nicer.</p>
<p>There is one complaint in that it still runs Android 2.2. instead of 2.3.
Perhaps I shall learn patience. I am not sure if I will root this one. Hopefully
I don&rsquo;t quite get bored of it as I did with the HTC&rsquo;s.</p>
<p>I like the bunch of additional stuff that comes with the Motorola phone
including the Swype. I&rsquo;m not convinced that I&rsquo;ll want to give that up.</p>
<p>I&rsquo;ll just wait patiently for the gingerbread upgrade. Until then, I&rsquo;ll just
enjoy the other ways in which the device is awfully sweeeeet!</p>]]></content:encoded></item><item><title>Android - Parcel data to pass between Activities using Parcelable classes</title><link>https://icle.es/2010/04/26/android-parcel-data-to-pass-between-activities-using-parcelable-classes/</link><pubDate>Mon, 26 Apr 2010 21:46:31 +0000</pubDate><guid>https://icle.es/2010/04/26/android-parcel-data-to-pass-between-activities-using-parcelable-classes/</guid><description>&lt;p>Passing data between activities on android is unfortunately, not as simple as
passing in parameters. What we need to to do is tag these onto the intent. If
the information we need to pass across is a simple object like a String or
Integer, this is easy enough.&lt;/p>
```java
String strinParam = "String Parameter";
Integer intParam = 5;

Intent i = new Intent(this, MyActivity.class);
i.putExtra("uk.co.kraya.stringParam", stringParam);
i.putExtra("uk.co.kraya.intParam", intParam);

startActivity(i);
```</description><content:encoded><![CDATA[<p>Passing data between activities on android is unfortunately, not as simple as
passing in parameters. What we need to to do is tag these onto the intent. If
the information we need to pass across is a simple object like a String or
Integer, this is easy enough.</p>
```java
String strinParam = "String Parameter";
Integer intParam = 5;

Intent i = new Intent(this, MyActivity.class);
i.putExtra("uk.co.kraya.stringParam", stringParam);
i.putExtra("uk.co.kraya.intParam", intParam);

startActivity(i);
```
<p>Passing in custom objects is a little more complicated. You could just mark the
class
as <a href="http://java.sun.com/javase/6/docs/api/java/io/Serializable.html">Serializable</a>
and let Java take care of this. However, on the android, there is a serious
performance hit that comes with using Serializable. The solution is to
use <a href="http://developer.android.com/reference/android/os/Parcelable.html">Parcelable</a>.</p>
```java
package uk.co.kraya.android.demos.Parcelable;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * @author Shriram Shri Shrikumar
 *
 * A basic object that can be parcelled to
 * transfer between objects
 *
 */
public class ObjectA implements Parcelable {

    private String strValue;
    private Integer intValue;

    /**
     * Standard basic constructor for non-parcel
     * object creation
     */
    public ObjectA() { ; };

    /**
     *
     * Constructor to use when re-constructing object
     * from a parcel
     *
     * @param in a parcel from which to read this object
     */
    public ObjectA(Parcel in) {
        readFromParcel(in);
    }

    /**
     * standard getter
     *
     * @return strValue
     */
    public String getStrValue() {
        return strValue;
    }

    /**
     * Standard setter
     *
     * @param strValue
     */
    public void setStrValue(String strValue) {
        this.strValue = strValue;
    }

    /**
     * standard getter
     *
     * @return
     */
    public Integer getIntValue() {
        return intValue;
    }

    /**
     * Standard setter
     *
     * @param intValue
     */
    public void setIntValue(Integer intValue) {
        this.intValue = intValue;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {

        // We just need to write each field into the
        // parcel. When we read from parcel, they
        // will come back in the same order
        dest.writeString(strValue);
        dest.writeInt(intValue);
    }

    /**
     *
     * Called from the constructor to create this
     * object from a parcel.
     *
     * @param in parcel from which to re-create object
     */
    private void readFromParcel(Parcel in) {

        // We just need to read back each
        // field in the order that it was
        // written to the parcel
        strValue = in.readString();
        intValue = in.readInt();
    }

    /**
     *
     * This field is needed for Android to be able to
     * create new objects, individually or as arrays.
     *
     * This also means that you can use use the default
     * constructor to create the object and use another
     * method to hyrdate it as necessary.
     *
     * I just find it easier to use the constructor.
     * It makes sense for the way my brain thinks ;-)
     *
     */
    public static final Parcelable.Creator CREATOR =
        new Parcelable.Creator() {
            public ObjectA createFromParcel(Parcel in) {
                return new ObjectA(in);
            }

            public ObjectA[] newArray(int size) {
                return new ObjectA[size];
            }
        };

}
```
<p>The intricacies of the class is described in the code above. There is now one
more special case. What if you have an object that references another object.
Clearly, they would both need to be Parcelable, but how would be integrate them.
ObjectB shows a parcelable embedded in another parcelable&hellip;</p>
```java
package uk.co.kraya.android.demos.Parcelable;

import android.os.Parcel;
import android.os.Parcelable;

public class ObjectB implements Parcelable {

    private ObjectA obj;
    private Long longVal;

    public ObjectB() { ; }

    public ObjectA getObj() {
        return obj;
    }

    /**
     *
     * Constructor to use when re-constructing object
     * from a parcel
     *
     * @param in a parcel from which to read this object
     */
    public ObjectB(Parcel in) {
        readFromParcel(in);
    }

    public void setObj(ObjectA obj) {
        this.obj = obj;
    }

    public Long getLongVal() {
        return longVal;
    }

    public void setLongVal(Long longVal) {
        this.longVal = longVal;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {

        // The writeParcel method needs the flag
        // as well - but thats easy.
        dest.writeParcelable(obj, flags);

        // Same as in ObjectA
        dest.writeLong(longVal);
    }

    /**
     *
     * Called from the constructor to create this
     * object from a parcel.
     *
     * @param in parcel from which to re-create object
     */
    private void readFromParcel(Parcel in) {

        // readParcelable needs the ClassLoader
        // but that can be picked up from the class
        // This will solve the BadParcelableException
        // because of ClassNotFoundException
        obj = in.readParcelable(ObjectA.class.getClassLoader());

        // The rest is the same as in ObjectA
        longVal = in.readLong();
    }

    /**
     *
     * This field is needed for Android to be able to
     * create new objects, individually or as arrays.
     *
     * This also means that you can use use the default
     * constructor to create the object and use another
     * method to hyrdate it as necessary.
     *
     * I just find it easier to use the constructor.
     * It makes sense for the way my brain thinks ;-)
     *
     */
    public static final Parcelable.Creator CREATOR =
        new Parcelable.Creator() {
            public ObjectB createFromParcel(Parcel in) {
                return new ObjectB(in);
            }

            public ObjectB[] newArray(int size) {
                return new ObjectB[size];
            }
        };
}
```
<p>When writing the parcel, we need to pass in the flags - which is easy enough.
When reading the parcel, we need the classloader, which can be picked up from
destination class of the parcelable. Again easy!</p>
<p>Finally, passing a parcelable object to an intent</p>
```java
ObjectA obj = new ObjectA();

// Set values etc.

Intent i = new Intent(this, MyActivity.class);
i.putExtra("com.package.ObjectA", obj);

startActivity(i);
```
<p>Almost too easy - right?</p>
<p>and to read the values,</p>
```java
public class MyActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle b = getIntent().getExtras();
        ObjectA obj =
            b.getParcelable("com.package.ObjectA");
    }

}
```
<p>It it was any easier - we&rsquo;d all be out of a job ;-)</p>]]></content:encoded></item><item><title>Android - Managing Global Configuration</title><link>https://icle.es/2010/04/25/android-managing-global-configuratio/</link><pubDate>Sun, 25 Apr 2010 00:39:13 +0000</pubDate><guid>https://icle.es/2010/04/25/android-managing-global-configuratio/</guid><description>&lt;p>&lt;strong>The Problem&lt;/strong>&lt;/p>
&lt;p>Accessing preferences / configuration / settings from Android is actually pretty
straightforward as long as you are in an
&lt;a href="http://developer.android.com/reference/android/app/Activity.html" title="Activity">Activity&lt;/a>.
To read:&lt;/p>
```java
// PREFS_FILENAME = "nameOfPrefsFile";

SharedPreferences pref = getSharedPreferences(PREFS_FILENAME,
 Context.MODE_PRIVATE);

String string = pref.getString("key", "default");
// 1 is the default if key isn't set
int intValue = pref.getInt("intKey", 1);

// and so on
```
&lt;p>&lt;a href="http://developer.android.com/reference/android/content/SharedPreferences.html" title="SharedPreferences">SharedPreference&lt;/a>s
is the key class. To write, you also need the
[SharedPreferences.Editor](&lt;a href="http://developer.android.com/reference/android/content/SharedPreferences.Editor.html%7b">http://developer.android.com/reference/android/content/SharedPreferences.Editor.html{&lt;/a>
class, as follows:&lt;/p>
```java
// PREFS_FILENAME = "nameOfPrefsFile";
SharedPreferences pref = getSharedPreferences(PREFS_FILENAME,
 Context.MODE_PRIVATE);
Editor editor = pref.edit();
editor.putString("key", "value");
editor.putInt("intKey", 5);

// Until you call commit, the changes will not
// be written, so don't forget this step
editor.commit();
```
&lt;p>In general however, you will need access to settings in more than one activity
and it seems a bit wasteful to get these bits littered through the application.
Since I am lazy and like to write things just once, I  separated all the prefs
stuff into one class called Settings.&lt;/p></description><content:encoded><![CDATA[<p><strong>The Problem</strong></p>
<p>Accessing preferences / configuration / settings from Android is actually pretty
straightforward as long as you are in an
<a href="http://developer.android.com/reference/android/app/Activity.html" title="Activity">Activity</a>.
To read:</p>
```java
// PREFS_FILENAME = "nameOfPrefsFile";

SharedPreferences pref = getSharedPreferences(PREFS_FILENAME,
                              Context.MODE_PRIVATE);

String string = pref.getString("key", "default");
// 1 is the default if key isn't set
int intValue = pref.getInt("intKey", 1);

// and so on
```
<p><a href="http://developer.android.com/reference/android/content/SharedPreferences.html" title="SharedPreferences">SharedPreference</a>s
is the key class. To write, you also need the
[SharedPreferences.Editor](<a href="http://developer.android.com/reference/android/content/SharedPreferences.Editor.html%7b">http://developer.android.com/reference/android/content/SharedPreferences.Editor.html{</a>
class, as follows:</p>
```java
// PREFS_FILENAME = "nameOfPrefsFile";
SharedPreferences pref = getSharedPreferences(PREFS_FILENAME,
                              Context.MODE_PRIVATE);
Editor editor = pref.edit();
editor.putString("key", "value");
editor.putInt("intKey", 5);

// Until you call commit, the changes will not
// be written, so don't forget this step
editor.commit();
```
<p>In general however, you will need access to settings in more than one activity
and it seems a bit wasteful to get these bits littered through the application.
Since I am lazy and like to write things just once, I  separated all the prefs
stuff into one class called Settings.</p>
<p>It has a constructor which takes a
<a href="http://developer.android.com/reference/android/content/Context.html" title="Context">Context</a>
(We need this to access the SharedPreferences Object). It also has setters and
getters for each property being saved. This example, just saves/retrieves a
username and password.</p>
```java
import uk.co.kraya.HelloWS;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * @author Shriram Shri Shrikumar
 *
 * This class stores and manages all the preferences
 * for the application.
 *
 */
public class Settings {

    private static final String USERNAME_KEY = "username";
    private static final String PASSWORD_KEY = "password";

    private static final String USERNAME_DEFAULT = "username";
    private static final String PASSWORD_DEFAULT = "password";

    private final SharedPreferences settings;

    /**
     * @param act The context from which to pick SharedPreferences
     */
    public Settings (Context act) {
         settings = act.getSharedPreferences(HelloWS.PREFS_NAME, Context.MODE_PRIVATE);
    }

    /**
     * Set the username in the preferences.
     *
     * @param username the username to save into prefs
     */
    public void setUsername(String username) {
        Editor editor = settings.edit();
        editor.putString(USERNAME_KEY, username);
        editor.commit();
    }

    /**
     * @return the username from the prefs
     */
    public String getUsername() {
        return settings.getString(USERNAME_KEY, USERNAME_DEFAULT);
    }

    /**
     *
     * Set the password in the preferences.
     *
     * @param password password to save into prefs
     */
    public void setPassword(String password) {
        Editor editor = settings.edit();
        editor.putString(PASSWORD_KEY, password);
        editor.commit();
    }

    /**
     * @return the password stored in prefs
     */
    public String getPassword() {
        return settings.getString(PASSWORD_KEY, PASSWORD_DEFAULT);
    }

        // Check if there are any stored settings.
        // can be used to automatically load the settings page
        // where necessary
    public boolean hasSettings() {
        // We just check if a username has been set
        return (!settings.getString(USERNAME_KEY, "").equals(""));
    }

}
```
<p>Nothing particularly exciting. Now, how do we access this. The Android framework
has a neat little feature that is not very well documented and it involved the
use of the
<a href="http://developer.android.com/reference/android/app/Application.html">Application</a>
class. If you inherit from this class, and point to it in the manifest file, it
will get initialised first before any other objects. This is an ideal place for
bits that need global access. You could use Singletons or static fields but this
works with the framework.</p>
<p>There are two parts to making this work</p>
<p>The application class:</p>
```
public class MyApp extends Application {

    private Settings settings;

    @Override
    public void onCreate() {
        settings = new Settings(this);

    }

    public Settings getSettings() {
        return settings;
    }

}
```
<p>The <code>onCreate</code> method on <code>MyApp</code> will be called before <code>onCreate</code> on any of the
Activities. The Settings class described above, needs a Context to be passed in.
Lucky for us ;-) Application is also a Context.</p>
<p>You also need to wire it into the <code>AndroidManifest.xml</code>. You need to add the
<a href="http://developer.android.com/guide/topics/manifest/application-element.html#nm">android:name</a>
element into the
<a href="http://developer.android.com/guide/topics/manifest/application-element.html">application tag</a>{</p>
```xml
<application android:name="com.package.MyApp" android:icon="@drawable/icon" android:label="@string/app_name">
```
<p>Now that is all wired in, accessing the settings object from any activity is
simple:</p>
```java
MyApp app = (MyApp) getApplicationContext();

Settings settings = app.getSettings();
```
<p>Easy - right? While you won&rsquo;t be able to access the application subclass outside
of a context, the Setting class, with its local context variable can be passed
around with impunity :-D</p>]]></content:encoded></item><item><title>Android - Multi-line Select List</title><link>https://icle.es/2010/04/19/android-multi-line-select-list/</link><pubDate>Mon, 19 Apr 2010 23:37:54 +0000</pubDate><guid>https://icle.es/2010/04/19/android-multi-line-select-list/</guid><description>&lt;p>It turns out that it is surprisingly easy to add a multi line select list to the
UI. There are four main parts to it. The layout file, a subclass to the adapter,
the activity and of course the data itself.&lt;/p>
&lt;p>Lets start with the data. For the sake of this demo, lets use a simple contact
list:&lt;/p>
```java
package uk.co.kraya.android.demos.MultiLineList.domain;

public class Contact {

 private String firstName;

 private String lastName;

 private String mobile;

 public String getFirstName() {
 return firstName;
 }

 public void setFirstName(String firstName) {
 this.firstName = firstName;
 }

 public String getLastName() {
 return lastName;
 }

 public void setLastName(String lastName) {
 this.lastName = lastName;
 }

 public String getMobile() {
 return mobile;
 }

 public void setMobile(String mobile) {
 this.mobile = mobile;
 }

}
```</description><content:encoded><![CDATA[<p>It turns out that it is surprisingly easy to add a multi line select list to the
UI. There are four main parts to it. The layout file, a subclass to the adapter,
the activity and of course the data itself.</p>
<p>Lets start with the data. For the sake of this demo, lets use a simple contact
list:</p>
```java
package uk.co.kraya.android.demos.MultiLineList.domain;

public class Contact {

    private String firstName;

    private String lastName;

    private String mobile;

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

}
```
<p>Some straightforward fields and getters/setters</p>
<p>Next, we need an Adapter. For this one, we will use
a <a href="http://developer.android.com/reference/android/widget/ArrayAdapter.html">ArrayAdapter</a>.
We will extend it so that we can override
the <a href="http://developer.android.com/reference/android/widget/Adapter.html#getView%28int,%20android.view.View,%20android.view.ViewGroup%29">getView method.</a></p>
```java
package uk.co.kraya.android.demos.MultiLineList.domain.adapters;

import java.util.List;

import uk.co.kraya.android.demos.MultiLineList.domain.Contact;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TwoLineListItem;

public class ContactArrayAdapter extends ArrayAdapter {

    private final int resourceId;

    public ContactArrayAdapter(Context context, int textViewResourceId, List objects) {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Contact c = getItem(position);

        // if the array item is null, nothing to display, just return null
        if (c == null) {
            return null;
        }

        // We need the layoutinflater to pick up the view from xml
        LayoutInflater inflater = (LayoutInflater)
                        getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        // Pick up the TwoLineListItem defined in the xml file
        TwoLineListItem view;
        if (convertView == null) {
            view = (TwoLineListItem) inflater.inflate(resourceId, parent, false);
        } else {
            view = (TwoLineListItem) convertView;
        }

        // Set value for the first text field
        if (view.getText1() != null) {
            view.getText1().setText(c.getFirstName() + " " + c.getLastName());
        }

        // set value for the second text field
        if (view.getText2() != null) {
            view.getText2().setText("mobile: " + c.getMobile());
        }

        return view;
    }

}
```
<p>The key bit here is the getView method. We pick up
the <a href="http://developer.android.com/reference/android/view/LayoutInflater.html">LayoutInflater</a>
which we can use to pick up the view that defines
the <a href="http://developer.android.com/reference/android/widget/TwoLineListItem.html">TwoLineListItem</a>
view. This allows us to use two different snippets of text as part of the list.
We then pick up the each of
the <a href="http://developer.android.com/reference/android/widget/TextView.html">TextView</a>
items and set the text against them. The formatting of these item are defined in
the xml file.</p>
<p>The TwoLineListItem class also defines a placeholder for the selectedIcon. Check
the documentation for more info.</p>
<p>The xml file for the layout goes as follows:</p>
```xml
<?xml version="1.0" encoding="utf-8"?>
<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView android:id="@android:id/text1"
        android:layout_marginTop="1dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15sp"
        android:textStyle="bold" />

    <TextView android:id="@android:id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@android:id/text1"
        android:layout_alignLeft="@android:id/text1"
        android:paddingBottom="4dip"
        android:includeFontPadding="false"
        android:textSize="15sp"
        android:textStyle="normal" />

</TwoLineListItem>
```
<p>As you can see, we are just defining a TwoLineListItem element with two embedded
TextItems. Tthe android:id parts are important. It ensures that the getText1()
and getText2() methods work as expected!</p>
<p>Finally, we have the activity. In fact, we will be using a
<a href="http://developer.android.com/reference/android/app/ListActivity.html">ListActivity</a>
as follows:</p>
```java
package uk.co.kraya.android.demos.MultiLineList;

import java.util.ArrayList;
import java.util.List;

import uk.co.kraya.android.demos.MultiLineList.domain.Contact;
import uk.co.kraya.android.demos.MultiLineList.domain.adapters.ContactArrayAdapter;
import android.app.ListActivity;
import android.os.Bundle;

public class MultiLineListDemo extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(new ContactArrayAdapter(this, R.layout.main, getContacts()));
    }

    private List getContacts() {

        List contacts = new ArrayList();

        Contact c;

        c = new Contact();
        c.setFirstName("Shriram");
        c.setLastName("Shrikumar");
        c.setMobile("07777777777");

        contacts.add(c);

        c = new Contact();
        c.setFirstName("John");
        c.setLastName("Doe");
        c.setMobile("MOBILE.NUMBER");

        contacts.add(c);

        return contacts;

    }
}
```
<p>getContacts clearly just creates a couple of contacts for the sake of the demo.
its the setListAdapter that is the key here. It creates a new
ContactArrayAdapter that we have written, passes in the context (which is just
the current activity), a resource ID and a List of items to display.</p>
<p>Run it and you should see something like:</p>
<p>
  <img src="/assets/2010/04/multilineselectdemo.png" alt="">

</p>
<p>So easy when you know how. I believe could use a View or a ViewGroup as needed
instead of the TwoLineListItem but I shall leave that to you to discover.</p>
<p>I have included all the files that I created/modified but if you want the whole
project tarred up, just drop me a note ;-)</p>]]></content:encoded></item></channel></rss>