如何自定义列表字段项?
我是黑莓开发的新手。我的应用程序包含五个列表项,每个列表项都有字符串。我的要求是,当选择一个单元格时,它应该放大,其他项目自动调整其中的空间。 我为列表项采用了两种类型的图像,一种用于一般视图,另一种用于在用户单击它时显示所选项目,该图像比以前的高度更高。
但问题是,当我选择一个项目时,它会放大并重叠在下一个项目上,并且不会显示完整的项目,也不会调整它们之间的空间。 谁能给我这个问题的解决方案。我正在使用以下代码片段...
_listField.setCallback(this);
_listField.setRowHeight(45);
_listField.setChangeListener(this);
public void drawListRow(ListField arg0, Graphicsgraphics, int index, int y, int 宽度) {
if (listFieldIndex != index) {
graphics.drawBitmap(0, y, listBkgrnd.getWidth(), listBkgrnd
.getHeight(), listBkgrnd, 0, 0);
graphics.setColor(0xAA0000);
graphics.setFont(this.getFont().derive(Font.BOLD, 17));
graphics.drawText(((Station) _stationList.elementAt(index))
.getStationName(), 15, y + 15, 0,
(listBkgrnd.getWidth() - 70));
graphics.setColor(0x770000);
graphics.setFont(this.getFont().derive(Font.PLAIN, 13));
// graphics.drawText(
// ((Station) _stationList.elementAt(index)).getCT(), 15,
// y + 40, 0, (listBkgrnd.getWidth() - 65));
} else {
graphics.drawBitmap(0, y, playBkgrnd.getWidth(), playBkgrnd
.getHeight(), playBkgrnd, 0, 0);
graphics.setColor(0xAA0000);
graphics.setFont(this.getFont().derive(Font.BOLD, 17));
graphics.drawText(((Station) _stationList.elementAt(index))
.getStationName(), 15, y + 15, 0,
(playBkgrnd.getWidth() - 70));
graphics.setColor(0x770000);
graphics.setFont(this.getFont().derive(Font.PLAIN, 13));
graphics.drawText(
s.getCT(), 15,
y + 40, 0, (playBkgrnd.getWidth() - 65));
}
}
I am new to Blackberry development.My application contain five list items having strings each item.My requirement is when one cell is selected it should enlarge and other items adjust space automatically among them.
I took two types of images for list items one for general view and one for displaying the selected item when user clicked on it which is of more height than previous.
But the problem is when I selected one item it is enlarging and overlapped on the next item and is not displaying full item and not adjusting the space among them.
can anyone give me the solution for this. I am using the following code snippet....
_listField.setCallback(this);
_listField.setRowHeight(45);
_listField.setChangeListener(this);
public void drawListRow(ListField arg0, Graphics graphics, int index,
int y, int width) {
if (listFieldIndex != index) {
graphics.drawBitmap(0, y, listBkgrnd.getWidth(), listBkgrnd
.getHeight(), listBkgrnd, 0, 0);
graphics.setColor(0xAA0000);
graphics.setFont(this.getFont().derive(Font.BOLD, 17));
graphics.drawText(((Station) _stationList.elementAt(index))
.getStationName(), 15, y + 15, 0,
(listBkgrnd.getWidth() - 70));
graphics.setColor(0x770000);
graphics.setFont(this.getFont().derive(Font.PLAIN, 13));
// graphics.drawText(
// ((Station) _stationList.elementAt(index)).getCT(), 15,
// y + 40, 0, (listBkgrnd.getWidth() - 65));
} else {
graphics.drawBitmap(0, y, playBkgrnd.getWidth(), playBkgrnd
.getHeight(), playBkgrnd, 0, 0);
graphics.setColor(0xAA0000);
graphics.setFont(this.getFont().derive(Font.BOLD, 17));
graphics.drawText(((Station) _stationList.elementAt(index))
.getStationName(), 15, y + 15, 0,
(playBkgrnd.getWidth() - 70));
graphics.setColor(0x770000);
graphics.setFont(this.getFont().derive(Font.PLAIN, 13));
graphics.drawText(
s.getCT(), 15,
y + 40, 0, (playBkgrnd.getWidth() - 65));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
BlackBerry 上的列表字段假定所有行的高度相同。
要获得您想要的效果,请在
VerticalFieldManager
中使用一堆可选字段,您将获得与 ListField 类似的效果。确保您的项目可聚焦,并在它们获得或失去焦点时调用updateLayout
,然后在您的layout
方法中,根据字段是否获得焦点来设置字段的高度。类似下面的大纲:List fields on BlackBerry assume that all rows are the same height.
To get the kind of effect you want, use a bunch of selectable fields in a
VerticalFieldManager
, you'll get a similar effect to a ListField. Be sure to make your items focusable, and callupdateLayout
whenever they gain or lose focus, then in yourlayout
method, set the field's height according to whether or not it's focused. Something like the following outline: