Skip to content
Provide an Android list with the look & field and sections of iOS UITableView
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

What is UITableView4Android ?

UITableView4Android is an Android library providing a customized ListView with the look & field and behavior of UITableView on iOS.

Note: This is not a recommended Android UI pattern! This repo is only here in case your client insist to do this.


Some companies are asking for mobile applications that must have the same appearance both on Android and iOS. And of course, iOS is almost always the version to fit... List views are one the most difficult component to adapt on Android because of corners and borders to set correctly.

Usage example

1. Declare layout

Add the UITableView in your layout :

	android:layout_alignParentTop="true" >

2. Implement the adapter

This UITableView is a sub-class of Android ListView and need an implementation of UITableViewAdapter.

class SimpleUITableViewAdapter extends UITableViewAdapter {

	private int[] color_line1_default;
	private int[] color_line2_default;
	private int[] color_line1_pressed;
	private int[] color_line2_pressed;

	public SimpleUITableViewAdapter() {
		// Prepare two sets of colors for odd and even lines
		color_line1_default = new int[] { getResources().getColor(R.color.base_start_color_line1_default), getResources().getColor(R.color.base_end_color_line1_default) };
		color_line2_default = new int[] { getResources().getColor(R.color.base_start_color_line2_default), getResources().getColor(R.color.base_end_color_line2_default) };
		color_line1_pressed = new int[] { getResources().getColor(R.color.base_start_color_line1_pressed), getResources().getColor(R.color.base_end_color_line1_pressed) };
		color_line2_pressed = new int[] { getResources().getColor(R.color.base_start_color_line2_pressed), getResources().getColor(R.color.base_end_color_line2_pressed) };

	public int numberOfGroups() {
		return 4;

	public int numberOfRows(int group) {
		return (group + 1) * 2;
	public UITableHeaderItem headerItemForGroup(Context context, IndexPath indexPath) {
		return new UITableHeaderItem("Group " + indexPath.getGroup());
	public UITableCellItem cellItemForRow(Context context, IndexPath indexPath) {
		String title = "Cell number " + indexPath.getRow() + " in group " + indexPath.getGroup();
		String subtitle = (indexPath.getRow() % 2 == 0) ? "Subtitle " + indexPath.getRow() : null;
		return new UITableCellItem(title, subtitle);

	public UITableHeaderView headerViewForGroup(Context context, IndexPath indexPath, UITableHeaderItem headerItem, UITableHeaderView convertView) {
		UITableHeaderView headerView;
		if (convertView == null) {
			// If the recycled view is null, we just creating one
			headerView = new UITableHeaderView(context, indexPath);
		} else {
			headerView = (UITableHeaderView) convertView;


		return headerView;

	public UITableCellView cellViewForRow(Context context, IndexPath indexPath, UITableCellItem cellItem, UITableCellView convertView) {
		UITableCellView cellView;
		if (convertView == null) {
			// If the recycled view is null, we just creating one with cell's commons parameters
			cellView = new UITableCellView(context, indexPath);
		} else {
			cellView = (UITableCellView) convertView;


		// Set alternated background color
		if (indexPath.getRow() % 2 == 0) {
			cellView.setBackgroundColor(color_line1_default, color_line1_pressed);
		} else {
			cellView.setBackgroundColor(color_line2_default, color_line2_pressed);

		return cellView;

3. Add listeners

Some listeners are avaible to handle click and long click on cells, headers and accessory's cells. Let's implement them all on our SimpleUITableViewAdapter.

public void onCellClick(IndexPath indexPath) {
	Toast.makeText(getApplicationContext(), "Cell clicked : " + indexPath, 1000).show();

public boolean onCellLongClick(IndexPath indexPath) {
	Toast.makeText(getApplication(), "Cell long clicked : " + indexPath, 1000).show();
	return indexPath.getRow() % 2 == 0;	// Consume the long click one row out of two

public void onCellAccessoryClick(IndexPath indexPath) {
	Toast.makeText(getApplication(), "Cell accessory clicked : " + indexPath, 1000).show();

public void onHeaderClick(IndexPath indexPath) {
	Toast.makeText(getApplicationContext(), "Header clicked : " + indexPath, 1000).show();

public boolean onHeaderLongClick(IndexPath indexPath) {
	Toast.makeText(getApplicationContext(), "Header long clicked : " + indexPath, 1000).show();
	return indexPath.getGroup() % 2 == 0;	// Consume the long click one row out of two

4. Configure UITableView

Now, we have an implementation of UITableViewAdapter with all listeners added. It only remains to configure the UITableView.

SimpleUITableViewAdapter tableViewAdapter = new SimpleUITableViewAdapter();
tableView = (UITableView) findViewById(;


And here is the result.

Example result

You can’t perform that action at this time.