// Specify a data template for each item describing a block with four
// rows and
// two columns. Create a region so that the image will be displayed
// across
// four rows.
final DataTemplate dataTemplate =
new DataTemplate(_tableView, NUM_ROWS, NUM_COLUMNS) {
/**
* @see DataTemplate#getDataFields(int)
*/
public Field[] getDataFields(final int modelRowIndex) {
final Object[] data =
(Object[]) _tableModel.getRow(modelRowIndex);
final Field[] fields = new Field[data.length];
for (int i = 0; i < data.length; i++) {
if (data[i] instanceof Bitmap) {
fields[i] = new BitmapField((Bitmap) data[i]);
} else if (data[i] instanceof String) {
fields[i] =
new LabelField(data[i], Field.FOCUSABLE);
} else {
fields[i] = (Field) data[i];
}
}
return fields;
}
};
// Set the style and apply it to the data template via the
// setRowProperties() method
dataTemplate.createRegion(new XYRect(0, 0, 1, 4), _style);
dataTemplate.setRowProperties(0, new TemplateRowProperties(Font
.getDefault().getHeight()
+ (_style.getBorder() == null ? 0 : _style.getBorder().getTop()
+ _style.getBorder().getBottom())
+ (_style.getMargin() == null ? 0 : _style.getMargin().top
+ _style.getMargin().bottom)));
for (int i = 0; i < NUM_ROWS; i++) {
dataTemplate.createRegion(new XYRect(1, i, 1, 1), _style);
dataTemplate.setRowProperties(i, new TemplateRowProperties(Font
.getDefault().getHeight()
+ (_style.getBorder() == null ? 0 : _style.getBorder()
.getTop()
+ _style.getBorder().getBottom())
+ (_style.getMargin() == null ? 0 : _style.getMargin().top
+ _style.getMargin().bottom)));
}
// Calculate and programmatically set the width of the image section of
// the table
final int width =
IMAGE_WIDTH
+ (_style.getBorder() == null ? 0 : _style.getBorder()
.getTop()
+ _style.getBorder().getBottom())
+ (_style.getMargin() == null ? 0
: _style.getMargin().top
+ _style.getMargin().bottom);
dataTemplate
.setColumnProperties(0, new TemplateColumnProperties(width));
// Set the width of the text portion of the table
dataTemplate.setColumnProperties(1, new TemplateColumnProperties(
Display.getWidth() - width));
// Apply the template to the view
_tableView.setDataTemplate(dataTemplate);
dataTemplate.useFixedHeight(true);
}