[Deprecated] Create iOS-like tables (UITableView) for Android, using UIKit object model.

Overview

THIS PROJECT IS NO LONGER MAINTAINED

Please refer to Android docs to customize lists depending on your needs.

ATableView

ATableView

Summary

ATableView intends to imitate same object model proposed on UIKit for building tables, so it's not only limited on theming Android ListView. If you've some background on iOS development you may jump over some of the sections below, you'll find a lot of similarities with the native framework.

If not, you should be good with the examples included here and the demo project.

Updates

Documentation is a little outdated, please use it only for reference and stay close to the examples included on the demo project. Feel free to submit a bug if you find any issues using it.

How to use it

Creating tables

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
        
    // ATableViewStyle.Plain & Grouped supported.
    ATableView tableView = new ATableView(ATableViewStyle.Grouped, this);
        
    // don't forget to set the datasource, otherwise you'll get an exception.
    // it must be an object extending ATableViewDataSource, or ATableViewDataSourceExt (more on this later).
    tableView.setDataSource(new SampleATableViewDataSource());
        
    // delegates are optional, it must extend ATableViewDelegate.
    tableView.setDelegate(new SampleATableViewDelegate());
        
    FrameLayout container = (FrameLayout)findViewById(android.R.id.content);
    container.addView(tableView);
}

Implementing a data source

It's your responsability to implement the required methods when extending ATableViewDataSource. The following are supported:

public ATableViewCell cellForRowAtIndexPath(ATableView tableView, NSIndexPath indexPath); [Required]
public int numberOfRowsInSection(ATableView tableView, int section); [Required]
public int numberOfSectionsInTableView(ATableView tableView);

More on how this methods works can be found on the iOS UITableViewDataSource Protocol Reference.

Example

@Override
public ATableViewCell cellForRowAtIndexPath(ATableView tableView, NSIndexPath indexPath) {
    final String cellIdentifier = "CellIdentifier";
        
    // ATableViewCellStyle.Default, Subtitle, Value1 & Value2 supported.
    ATableViewCellStyle style = ATableViewCellStyle.Default;
        
    // reuse cells. if the table has different row types it will result on performance issues.
    // Use ATableViewDataSourceExt on this cases.
    // please notice we ask the datasource for a cell instead the table as we do on ios.
    ATableViewCell cell = dequeueReusableCellWithIdentifier(cellIdentifier);
    if (cell == null) {
        cell = new ATableViewCell(style, cellIdentifier, MainActivity.this);
        // ATableViewCellSelectionStyle.Blue, Gray & None supported. It defaults to Blue.
        cell.setSelectionStyle(ATableViewCellSelectionStyle.Blue);
    }
    
    // set title.
    cell.getTextLabel().setText("Buenos Aires");
        
    // set detail text. careful, detail text is not present on every cell style.
    // null references are not as neat as in obj-c.
    TextView detailTextLabel = cell.getDetailTextLabel();
    if (detailTextLabel != null) {
        detailTextLabel.setText("Argentina");
    }
            
    return cell;
}
    
@Override
public int numberOfRowsInSection(ATableView tableView, int section) {
    // return number of rows for this section.
    if (section == 1) {
        return 4;
    }
        
    return 2;
}
    
@Override
public int numberOfSectionsInTableView(ATableView tableView) {
    // defaults to 1.
    return 2;
}

Table styles (ATableViewStyle)

All UITableViewStyle styles are supported. These are:

  • ATableViewStyle.Plain
  • ATableViewStyle.Grouped

Creating cells

You can use cell styles included by default, or extend ATableViewCell to create your own cells.

Cell styles (ATableViewCellStyle)

All UITableViewCellStyles styles are supported. These are:

  • ATableViewCellStyle.Default
  • ATableViewCellStyle.Subtitle
  • ATableViewCellStyle.Value1
  • ATableViewCellStyle.Value2

ATableViewCellStyle

Cell selection styles (ATableViewCellSelectionStyle)

All UITableViewCellSelectionStyle styles are supported These are:

  • ATableViewCellSelectionStyle.None
  • ATableViewCellSelectionStyle.Blue (Default)
  • ATableViewCellSelectionStyle.Gray

ATableViewCellSelectionStyle

Adding images to cells (imageView)

imageView is shown automatically when an image is defined for it, otherwise is hidden by default on each cell.

imageView

Example

Drawable drawable = getResources().getDrawable(R.drawable.some_image);
cell.getImageView().setImageDrawable(drawable);

Creating custom cells

Creating custom cells is as simple as extending ATableViewCellStyle and indicate the layout you want your cell to use.

Example

public class MyCustomCell extends ATableViewCell {
    private UILabel mCustomLabel;
    
    protected int getLayout(ATableViewCellStyle style) {
        // here it goes your custom cell layout.
        return R.layout.my_custom_cell;
    }
    
    public MyCustomCell(ATableViewCellStyle style, String reuseIdentifier, Context context) {
        super(style, reuseIdentifier, context);
        mCustomLabel = (UILabel)findViewById(R.id.custom_cell_label);
    }
    
    public UILabel getCustomLabel() {
        return mCustomLabel;
    }
}

Implementing a delegate

Adding a delegate to the table is optional. UITableViewDelegate defines many methods to describe how the table should look and behave. Only a few of them are currently supported on ATableViewDelegate. These are:

public void didSelectRowAtIndexPath(ATableView tableView, NSIndexPath indexPath);
public int heightForRowAtIndexPath(ATableView tableView, NSIndexPath indexPath);

Example

@Override
public void didSelectRowAtIndexPath(ATableView tableView, NSIndexPath indexPath) {
	// do something when the row is selected. rows are identified by its indexPath.    
}
		
@Override
public int heightForRowAtIndexPath(ATableView tableView, NSIndexPath indexPath) {
    // return height size on dip. defaults to 44 if not implemented.
    return 54;
}

Table data source additional methods (ATableViewDataSourceExt)

On the case you need to use different cell styles on the same table, you should extend ATableViewDataSourceExt to avoid performance issues when scrolling. This is necessary since Android ListView uses different pools for reusing cells, a pool for each cell type. ATableViewDataSourceExt is used to specify how many rows and pools should be created to run smoothly.

You'll have additionally to implement the following methods:

public int numberOfRowStyles(); [Required]
public int styleForRowAtIndexPath(NSIndexPath indexPath); [Required]

Example

@Override
public int numberOfRowStyles() {
    // number of different rows on the table.
    return 4;
}
    
@Override
public int styleForRowAtIndexPath(NSIndexPath indexPath) {
    // integer identifying the style for a cell at a given indexPath.
    return myOwnImplementationGetStyle(indexPath);
}

Extra stuff

UILabel

UILabel uses internally Roboto font, which make labels look-alike in iOS and it's rendered great by Android. Roboto font is available from ICS and above, so it should be included on your project /assets folder in order to make it work for any version.

Both Roboto-Regular.ttf and Roboto-Bold.ttf are included on the demo project. On the case you don't include these files, text will render using the default font available.

License

Copyright 2012 Diego Acosta - Contact me at [email protected] / @nakardo

Released under the Apache 2.0. license.

Roboto font by Google Android - Licensed under the Apache License.

Awesome Android PSD images by slaveoffear.

You might also like...
Insanely easy way to work with Android Database.

Sugar ORM Insanely easy way to work with Android databases. Official documentation can be found here - Check some examples below. The example applicat

Android ORM
Android ORM

Shillelagh Shillelagh is an sqlite library. It was built to make life easier. The entire library was built around simplicity when using sqlite in Andr

Compile-time active record ORM for Android

Ollie Compile-time active record ORM for Android. Multiple mapping methods. SQLiteDatabase-like interface (QueryUtils.java). Lightweight query builder

requery - modern SQL based query & persistence for Java / Kotlin / Android
requery - modern SQL based query & persistence for Java / Kotlin / Android

A light but powerful object mapping and SQL generator for Java/Kotlin/Android with RxJava and Java 8 support. Easily map to or create databases, perfo

A blazing fast, powerful, and very simple ORM android database library that writes database code for you.
A blazing fast, powerful, and very simple ORM android database library that writes database code for you.

README DBFlow is fast, efficient, and feature-rich Kotlin database library built on SQLite for Android. DBFlow utilizes annotation processing to gener

Core Data for Android

NexusData Core Data for Android NexusData is an object graph and persistence framework for Android. It allows for organizing and managing relational d

An Android library that makes developers use SQLite database extremely easy.

LitePal for Android 中文文档 LitePal is an open source Android library that allows developers to use SQLite database extremely easy. You can finish most o

Active record style SQLite persistence for Android

ActiveAndroid ActiveAndroid is an active record style ORM (object relational mapper). What does that mean exactly? Well, ActiveAndroid allows you to s

Insanely easy way to work with Android Database.

Sugar ORM Insanely easy way to work with Android databases. Official documentation can be found here - Check some examples below. The example applicat

Comments
  • setContentOffset is not available

    setContentOffset is not available

    ATableView has most of the features which UITableView has. But I am not able to find setContentOffset function. Or do I have to use ListView specific functions ??

    opened by alok-rao 1
Owner
Diego Acosta
👾
Diego Acosta
SquiDB is a SQLite database library for Android and iOS

Most ongoing development is currently taking place on the dev_4.0 branch. Click here to see the latest changes and try out the 4.0 beta. Introducing S

Yahoo 1.3k Dec 26, 2022
A simple NoSQL client for Android. Meant as a document store using key/value pairs and some rudimentary querying. Useful for avoiding the hassle of SQL code.

SimpleNoSQL A simple NoSQL client for Android. If you ever wanted to just save some data but didn't really want to worry about where it was going to b

Colin Miller 389 Sep 25, 2022
An Android helper class to manage database creation and version management using an application's raw asset files

THIS PROJECT IS NO LONGER MAINTAINED Android SQLiteAssetHelper An Android helper class to manage database creation and version management using an app

Jeff Gilfelt 2.2k Dec 23, 2022
Collection of Kotlin APIs/tools to make using Realm Mobile database easier

Compass Kotlin API and tools to make working with Realm easier Components Compass is designed to make working with Realm easier through collection of

Arunkumar 16 Oct 4, 2022
To-Do App using Modern Declarative UI Toolkit called Jetpack Compose

Daedalus-Scheduler To-Do App using Modern Declarative UI Toolkit called Jetpack Compose The Brief App that searches recipes from the api spoonacular A

null 0 Jan 6, 2022
Newyork-book-listings - New york book listings using API from nytimes

New York Book Listings Project This is a project developed in Android Studio whi

Kushagra Jaiswal 0 Jan 8, 2022
Kotlin-Exposed-SQL - Example of using Exposed with Kotlin for the consumption of relational SQL Databases

Kotlin Exposed SQL Sencillo ejemplo sobre el uso y abuso de Exposed ORM de Jetbr

José Luis González Sánchez 3 Jun 14, 2022
Active record style SQLite persistence for Android

ActiveAndroid ActiveAndroid is an active record style ORM (object relational mapper). What does that mean exactly? Well, ActiveAndroid allows you to s

Michael Pardo 4.7k Dec 29, 2022
A blazing fast, powerful, and very simple ORM android database library that writes database code for you.

README DBFlow is fast, efficient, and feature-rich Kotlin database library built on SQLite for Android. DBFlow utilizes annotation processing to gener

Andrew Grosner 4.9k Dec 30, 2022
greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.

Check out ObjectBox Check out our new mobile database ObjectBox (GitHub repo). ObjectBox is a superfast object-oriented database with strong relation

Markus Junginger 12.6k Jan 3, 2023