Building Mobile Enterprise Applications : webMethods Mobile Development Help : Building the User Interface for a Mobile Application : Using a Content Provider to Populate a ListView
Using a Content Provider to Populate a ListView
Use a ListView object to display a list of items. You can populate a ListView object using a ContentProvider object to retrieve data from a data source. Mobile Development supports DynamicDataSource, RESTDataSource and EntityDataSource . For more information about data sources, see Objects to Use for Content Providers or Content Adapters.
Note:  
Instead of using a ContentProvider, you can programmatically populate the ListView. For more information, see Programmatically Populating a ListView.
Tip:  
If your ListViews requires displaying more than one Template instance, it is recommend to use the ContentAdapter.
Objects to Add to the Application Model
1. Add a ListView object to your application (or use a template containing a ListViewElement object).
2. Add a data source to your application, as a child of the Datasources node. This can be a DynamicDataSource, a RESTDataSource or an EntityDataSource .
3. Add a ContentProvider object to the ListView object. The ContentProvider object indicates from where you obtain data and the template to be used to present the data. Set the following properties:
Property
Description
List Data Source
Required. Specifies the data source.
No Rows Template
Optional. A template that is to be shown when the data source of the ContentProvider contains no elements.
Reload On Transition To
Select this if the ContentProvider is to be reloaded each time this view is accessed.
Row Template
Required. A template used to show the contents of the ListView.
4. Add one or more TemplateDataBinding objects to the ContentProvider object. A TemplateDataBinding maps a control contained in the RowTemplate of the ContentProvider with a given set of data identified by the Expression property. Set the following properties:
Property
Description
Control
Required. Select a control that is contained in the RowTemplate of the ContentProvider.
Data Source
Select the data source to populate the data for this control.
Expression
Enter an expression value to identify the data.
5. Optional. Add a RowSelectionListener to react on the user interaction with the ListView.
6. Optional. Add a Pagination object if you want to display the contents of the ListView on different pages. Set the following properties:
Property
Description
Max Number Per Page
The maximum number of cells displayed per page.
Next Page Template
A triggerable object (such as a Button) which needs to be triggered in order to load the next page.
Previous Page Template
A triggerable object (such as a Button) which needs to be triggered in order to load the previous page.
In addition, you can add templates to customize the ListView:
Templates
Template for...
Description
List item
Required. You must create a template that defines how to display a single item from the data source.
Typically, you create a template for a Table or TableButton object.
You reference this template in the ContentProvider object’s Template property.
List header
Optional. You can create a template to provide a header for the ListView. For example, you might create a template for an object like a Textfield or an Image.
If you want to provide a header for the ListView, specify the template in the ListView object’s List View Header property.
List separator
Optional. You can create a template for an object that you want to display between each list item in the ListView. For example, you might create a template for an object like a Separator, Spacer, or Image object.
If you want to provide a separator for the list of data, specify the template in the ListView object’s Separator property.
Control to show when reloading data
Optional. You can create a template for an object that the application will display when the application is accessing the data source to refresh the data. For example, you might create a template for an object like a ProgressAnim, Image, or Textfield object.
If you want the application to display an object when refreshing the data, specify the template in the ListView object’s Show On Reload property.
Control to display the next page of results
Conditionally required. Create a template for an object, for example, a Button object, that a user selects at run time to display the next page of results.
This template is required if you are using the Pagination object. You specify this template in the Pagination object’s Next Page Template property.
Control to display the previous page of results
Conditionally required. Create a template for an object, for example, a Button object, that a user selects at run time to display the previous page of results.
This template is required if you are using the Pagination object. You specify this template in the Pagination object’s Previous Page Template property.
If you decided to use a RESTDataSource, you also need to specify a RESTful service which will be triggered by the data source. For more information, see Adding Services to a Mobile Project.
Example: How to Use Expressions with a RESTDataSource
Consider you have a RESTful service that has a getEmployeeInfo method that returns information about employees. The following illustrates a sample JSON response given by the service:
{
"Employees": [
{
"ID" : "19",
"name" : "Leanna Jones",
"Department": {
"name" : "Research",
"location" : "Boston"
}},
{
"ID" : "30",
"name" : "Zane Smith",
"Department": {
"name" : "Research",
"location" : "Reston"
}}
]
}
If you like to add a ListView containing all employees, you need to set the ContentProvider object’s Expression property to Employees. The ListView will then contain two elements. To bind employees information to a particular template, you need to use an expression which is now relative to Employees. Having a template which visualizes the employee name and department name of each employee, you need to add two TemplateDataBinding objects with an Expression property pointing to name and Department.name.
Copyright © 2007-2017 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback