Quick Start Guide

Create Some Data

So far when we run our project we see little more than an empty grid. It’s about time we added some data! Typically this data will be a collection of ‘data objects’ that are used within your application, this could be a collection of emails, contacts, flight details … all sorts of things! For the purposes of this quick-start guide we’ll create some dummy data, using the theme of Person objects.

Create a Person Object

Right-click on the package containing QuickStartActivity and select New > Java Class. Type Person as the Name and click OK. Modify Person.java so that it looks like the following:

public class Person {

    public final String name;
    public final int age;

    public Person(String name, int age) {
       this.name = name;
       this.age = age;

Create a List of Person Objects

Now we have our Person object we need to instantiate some Persons with real data, and get them into a nice list which our grid can then use.

Back in QuickStartActivity.java, in the onCreate method add the following code:

final List<Person> people = new ArrayList<Person>();
people.add(new Person("Archie", 25));
people.add(new Person("Alexander", 15));
people.add(new Person("Jenny", 42));
people.add(new Person("Madison", 60));
people.add(new Person("Joanna", 32));

As before you will need to import some classes to make it compile.

Note: in the QuickStart sample app we use the PersonGenerator class to generate a longer list of Person objects for us but for brevity we've done it manually above!

<< Previous: Create a basic grid | Next: Create some columns >>