Showing posts from December, 2010

Playing with lists in Android - Part II

I hope you already read my first topic about listView. In part II, I am just extending the part I topic. So please read part I before reading part II.

In this, I am creating an adapter, in which each list item consists of two views, a TextView and an IMageView respectively. I am putting these two views in a relative layout. Then I am aligning the imageView to the right end of the layout using the addRule(). One more thing is, here I am putting a static image, that is the standard Android icon.

The adapter class is,

class MyAdapter extends BaseAdapter {

Context mContext;

public MyAdapter(Context context) {
mContext = context;

public int getCount() {
return list.size();

public Object getItem(int id) {
return id;

public long getItemId(int position) {
return position;

public View getView(int position, View convertView, ViewGroup parent) {
RelativeLayout layout = new RelativeLayout(mContext);