Android Tutorial Android Tutorial Part I

View the Project on GitHub FatFractal/hoodyoodoo

Add the Celebrity Model

In this section, we will create the native Java object class that the app will use. At this point, we will create a Celebrity object using standard Java patterns. This is your object definition, the NoServer Fraamework does not create dependencies in your code by requiring you to use our own proprietary object classes.

Creating the Celebrity Class

We will create a Celebrity data model that contains the following members:

Celebrity
{string} firstName the celebrity’s first name
{string} lastName the celebrity’s last name
{byte[]} imageData  the celebrity’s profile image
{string} gender the gender of the celebrity

You may notice that we are anticipating a byte array datatype for the image data as a native member of this class–stay tuned to see how that works.

In order to create the Celebrity class for your project in Eclipse, select the package to which you want to add it to (we used com.hoodyoodoo.droidapp.model), right click and select New > Class to bring up the Template Chooser for the new class file. We will use the standard Java class template. Enter "Celebrity" as the class name.

Click Finish to create a Celebrity.java class file.

We now edit the class to include the getters and setters for the members described above.

public class Celebrity {
	private String m_firstName = null;
	private String m_lastName = null;
	private byte[] m_imageData = null;
	private String m_gender = null;

	public	Celebrity() {}

	public String getFirstName()      {return m_firstName;}
	public String getLastName()       {return m_lastName;}
	public byte[] getImageData()      {return m_imageData;}
	public String getGender()         {return m_gender;}

	public void setFirstName(String param)      {m_firstName = param;}
	public void setLastName(String param)       {m_lastName = param;}
	public void setImageData(byte[] param)      {m_imageData = param;}
	public void setGender(String param)         {m_gender= param;}
}

The Celebrity object is now ready to interact with your API.

NEXT: Add in the Class