表出现问题 [英] problem in table appearing
问题描述
我使用以下代码创建了一个表.
I used following code to create a table.
import java.util.Vector;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.component.table.DataTemplate;
import net.rim.device.api.ui.component.table.TableController;
import net.rim.device.api.ui.component.table.TableModelAdapter;
import net.rim.device.api.ui.component.table.TableView;
import net.rim.device.api.ui.component.table.TemplateColumnProperties;
import net.rim.device.api.ui.component.table.TemplateRowProperties;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.decor.BackgroundFactory;
public class creatingTable extends MainScreen {
private DeviceTableModelAdapter _tableModel;
private Vector _devices;
private static final int NUM_ROWS =1;
private static final int ROW_HEIGHT = 50;
private static final int NUM_COLUMNS = 5;
public creatingTable(String id,String time,String name,String widthsetter)
{
super(Manager.NO_VERTICAL_SCROLL);
_devices = new Vector();
_tableModel = new DeviceTableModelAdapter();
Bitmap bitmap = Bitmap.getBitmapResource("icon.png");
{
Object[] row ={bitmap,id,time,name,widthsetter};
_tableModel.addRow(row);
// Set up table view and controller
TableView tableView = new TableView(_tableModel);
tableView.setDataTemplateFocus(BackgroundFactory.createLinearGradientBackground(Color.WHITE, Color.WHITE, Color.BLUEVIOLET, Color.BLUEVIOLET));
TableController tableController = new TableController(_tableModel, tableView);
tableController.setFocusPolicy(TableController.ROW_FOCUS);
tableView.setController(tableController);
// Specify a simple data template for displaying 3 columns
DataTemplate dataTemplate = new DataTemplate(tableView, NUM_ROWS, NUM_COLUMNS)
{
/**
* @see DataTemplate#getDataFields(int)
*/
public Field[] getDataFields(int modelRowIndex)
{
Object[] data = (Object[]) (_tableModel.getRow(modelRowIndex));
Field[] fields = {new BitmapField((Bitmap) data[0]), new LabelField((String) data[1]), new LabelField((String) data[2]),new LabelField((String) data[3]),new LabelField((String) data[4])};
return fields;
}
};
dataTemplate.useFixedHeight(true);
// Define regions and row height
dataTemplate.setRowProperties(0, new TemplateRowProperties(ROW_HEIGHT));
for(int i = 0; i < NUM_COLUMNS; i++)
{
dataTemplate.createRegion(new XYRect(i, 0,1,1));
dataTemplate.setColumnProperties(i, new TemplateColumnProperties(Display.getWidth() / NUM_COLUMNS));
}
// Apply the template to the view
tableView.setDataTemplate(dataTemplate);
add(tableView);
}}
private final static class BlackBerryDevice
{
private String _id;
private String _time;
private String _name;
private Bitmap _image;
private String _widthsetter;
BlackBerryDevice(Bitmap image,String id, String time, String name,String widthsetter)
{
_id = id;
_time = time;
_name = name;
_image = image;
_widthsetter = widthsetter;
}
public String getName()
{
return _name;
}
public String getId()
{
return _id;
}
public String getTime()
{
return _time;
}
public Bitmap getImage()
{
return _image;
}
public String getWidthsetter()
{
return _widthsetter;
}
}
private class DeviceTableModelAdapter extends TableModelAdapter
{
public int getNumberOfRows()
{
return _devices.size();
}
public int getNumberOfColumns()
{
return NUM_COLUMNS;
}
protected boolean doAddRow(Object row)
{
Object[] arrayRow = (Object[]) row;
_devices.addElement(new BlackBerryDevice( (Bitmap) arrayRow[0],(String) arrayRow[1],(String) arrayRow[2],(String) arrayRow[3],(String) arrayRow[4]));
return true;
}
protected Object doGetRow(int index)
{
BlackBerryDevice device = (BlackBerryDevice) _devices.elementAt(index);
Object[] row = {device.getImage(), device.getId(), device.getTime(),device.getName(),device.getWidthsetter()};
return row;
}
}
}
但是,当仅从pushScreen()调用该类时,它会提供一个表.它将出现在新屏幕中.但是我想像下面的代码那样调用该函数.
But it gives a table when only call to that class from pushScreen(). And it will appear in a new screen. But I want to call the function like following code.
creatingTable createTable=new creatingTable("id", "name", "album", "artistName");
但是它没有出现在桌子上.我应该对以上代码进行任何更改吗?谢谢
But It doesn''t appear the table. Should I make any changes to above code? Thanks
推荐答案
我认为它具有RMI API的性质:
I think it''s in the nature of the RMI API:
public class Test extends UiApplication
{
public static void main(String[] args)
{
UiApplication app = new Test();
app.enterEventDispatcher();
}
public Test()
{
pushScreen(new Test());
}
}
...因为UI应用程序具有功能pushScreen(Object)
来控制和管理屏幕内容
PS :请用大写字母命名您的班级,否则会遇到麻烦.从开发人员的角度来看,该名称也不正确:creatingTable
是典型的函数名称.请致电您的班级TableCreator
或类似名称.
...cause UI Application has control and manages the content of the screen with the function pushScreen(Object)
PS: Please name your class with a captial letter, you will get in trouble otherwise. Also is the name not correct from a developer''s point of view: creatingTable
is a typical function''s name. Please call your class TableCreator
or something similar.
这篇关于表出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!