This site has been archived. To learn more about our current products Ibexa Content, Ibexa Experience, Ibexa Commerce head over to the Ibexa Developer Portal
Thursday 13 October 2011 4:21:48 pm
Open Eclipse and select “New -> Android Project” from the “File” menu.
Enter the following information for the project:
Then, click the “Finish” button. You can inspect the project structure in the left pane.
Next, select “Window” -> “Android SDK and AVD Manager”. In the resulting dialog, select “Virtual devices” from the left panel and click the “New...” button.
Enter a name for your device, and choose an SDK target and screen resolution. Set the SD Card size to 12MiB (this is just to specify a card size for the Android emulator).
Our application will present multiple screens of information, one with a list view and the second with a details view. The Android SDK provides a convenient way to quickly display a list of data using a superclass called “android.app.ListActivity”. This activity already provides a list and content view, ready to use and populate with data.
Open “JSONListActivity.java” and change the superclass of “JSONListActivity” to extend “ListActivity”, removing the setting of the “ContentView” from the “onCreate” method.
public class JSONListActivity extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } }
Since we are going to operate on nodes, we need to create a business object that will hold node-related information. Select “New -> Class” from the “File” menu in the “src/com.ez” package. Enter “Node” as the class name, then click the “Finish” button.
Because we are going to pass node objects into the detail view, we need to implement a “java.io.Serializable” interface and implement the “serialVersionUID” property (this is a unique value used to recognize a serialized object; most IDEs can generate this for you, or you can create one yourself):
package com.ez; public class Node implements java.io.Serializable { private static final long serialVersionUID = 432509327611624427L; }
We will store the eZ Publish node ID and object name within the Node business object, thus we need to add two properties:
package com.ez; public class Node implements java.io.Serializable { private static final long serialVersionUID = 432509327611624427L; private int id; private String name; }
Next, we need to add getter and setter methods. Eclipse provides a very convenient way to automate this process. Select “Generate Getters and Setters...” from the “Source” menu. In the resulting window, mark the checkboxes for the “id” and “name” properties, then click the “OK” button.
Finally, we need to implement an override of the “toString()” method, which is going to be used to display the node name in the list view:
package com.ez; public class Node implements java.io.Serializable { private static final long serialVersionUID = 432509327611624427L; private int id; private String name; public void setId(int id) { this.id = id; } public int getId() { return id; } public void setName(String name) { this.name = name; } public String getName() { return name; } @Override public String toString() { return name; } }