3 つの列が必要で、複数の行を持つことができるテーブルを作成する必要があります。BlackBerry API バージョン 6 を使用しています。コードをデバッグしたところ、IllegalArgumentException
. このエラーを整理できません。
私のコードは次のとおりです。
public class designTableLayout extends MainScreen{
TableModel theModel = new TableModel();
theView = new TableView(theModel);
TableController theController = new TableController(theModel, theView,
TableController.FIELD_FOCUS);
theView.setController(theController);
HeaderTemplate theTemplate = new HeaderTemplate(theView, 1, 3);
theTemplate.createRegion(new XYRect(0,0,1,1));
theTemplate.createRegion(new XYRect(1,0,1,1));
theTemplate.createRegion(new XYRect(2,0,1,1));
theTemplate.setRowProperties(0, new TemplateRowProperties(60));
theTemplate.setColumnProperties(0, new TemplateColumnProperties(40));
theTemplate.setColumnProperties(1, new TemplateColumnProperties(40));
theTemplate.setColumnProperties(2, new TemplateColumnProperties(40));
theTemplate.useFixedHeight(true);
theView.setDataTemplate(theTemplate);
theModel.addRow(new String[]{"the","quick","brown"});// problem arises here
theModel.addRow(new String[]{"jumps","over","the"});
theModel.addRow(new String[]{"dog","the","quick"});
add(theView);
}
class HeaderTemplate extends DataTemplate {
LabelField field1 = new LabelField("field1");
LabelField field2 = new LabelField("field2");
LabelField field3 = new LabelField("field3");
public HeaderTemplate(DataView view,int rows,int columns){
super(view, rows, columns);
}
public Field[] getDataFields(int modelRowIndex) {
TableModel theModel = (TableModel) getView().getModel();
//Get the data for the row.
Object[] data = {field1, field2, field3};
data = (Object[]) theModel.getRow(modelRowIndex);
//Create a array to hold all fields.
Field[] theDataFields = new Field[data.length];
theDataFields[0] = new LabelField(field1/*, DrawStyle.ELLIPSIS*/);
theDataFields[1] = new LabelField(field2/*, DrawStyle.ELLIPSIS*/);
theDataFields[2] = new LabelField(field3/*, DrawStyle.ELLIPSIS*/);
return theDataFields;
}
}