Archives for category: Uncategorized

Finally I have had some success with TwoLineListItem’s. Here is how I implemented my solution.

Firstly, I created a simple class with two Strings and the associated getters and setters. This class represents each item in the list I will be creating later.

Next, I created a customised ArrayAdapter where I override the getView method. Inside the getView method you need to use the LayoutInflater to get the view from our main.xml file. Then we set the two lines of text.

Lastly, we extend the Activity class to extend from ListActivity. In the onCreate method (which is overridden) we call setListAdapter with our new custom ArrayAdapter as created above. From here we generate some data in our data class, add to a list and pass this list as a parameter to setListAdapter.

Code is below: apologies for the readability of the code. Hopefully I will get the hand of this blogging and fix it up to look good. <My Data Type>

package com.itemman.main;

public class item {

private String itemName;

private String itemDesc;

public String getitemName() {



publicvoid setitemName(String itemName) {

this.itemName = itemName;


public String getitemDesc() {



publicvoid setitemDesc(String itemDesc) {

this.itemDesc = itemDesc;



/res/layout/main.xml <The main layout file>




















</TwoLineListItem> <My custom ArrayAdapter class>

package com.itemman.main;

import java.util.List;

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 itemArrayAdapter extends ArrayAdapter {

private final int resourceId;

public itemArrayAdapter(Context context, int textViewResourceId, List objects) {

super(context, textViewResourceId, objects);

resourceId = textViewResourceId;



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

item t = (item) getItem(position);

if (t == null) {

return null;


LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

TwoLineListItem view;

if (convertView == null) {

view = (TwoLineListItem) inflater.inflate(resourceId, parent, false);

} else {

view = (TwoLineListItem) convertView;


if (view.getText1() != null) {



if (view.getText2() != null) {



return view;



So, setting up a list is no big deal. But the complexity increased by a multitude when I tried my hand at a twolinelistitem. So, I ask of anyone who reads this, what is the most efficient way of setting up a list with twolinelistitems? I’m going to go away again and re-try my hand at this but if you think you’ve got this down in an elegant / efficient manner than please let me know.

For anyone who hasn’t used what i’m talking about, here is some documentation I’ve found so far:

I’ll be back soon (hopefully) with my solution of which I want to be critiqued heavily on. I really want to make sure that as I learn Android development I am implementing best practices.

Good day.

Seriously, how are you?

My name is Bernie and I am about to head down the rabbit hole that is Android development. I am an experienced programmer in languages such as C, Java, VB .Net, Perl, PHP and a few others but I’ve been itching to get into some Android development. So I am now going to learn, with the help of others reading this blog, how to build Android applications. I will post my solutions and my issues and hope that others can help me out and that I can help out other beginners. This page will hopefully serve as my reference as I get further and further ahead in my development progress. I’m going to start by setting up my development environment which will involve downloading and installing Eclipse 3.7.2(

Today is day one, where will it take me?