Monday, August 1, 2011

Android List view with alternating row colors - contd

In one of previous blog Alternate row colors in ListView, we saw an adapter implementation to achieve alternate row colors. The article failed to explain how to use a custom adapter implementation. Using your own adapter is fairly simple. Look at the below source code for more.

SimpleCursorAdapter mAdapter = new AlternateRowCursorAdapter(this, R.layout.listrowLayout, cursor, columns, to);
this.setListAdapter(mAdapter);

Note that, I am using my own layout file(R.layout.listrowLayout) for laying out each of the row items.