如何自定义ObjectListField?

发布于 2024-09-16 09:16:42 字数 448 浏览 4 评论 0原文

是否可以按照以下设计自定义Objectfieldlist?

         ----------------------------
ROW#1    ROW NAME
         row details
         ---------------------------
ROW#2    ROW NAME
         row details
         ---------------------------  
ROW#3    ROW NAME
         row details
         ---------------------------

行名称的字体将大于行详细信息

基本上我需要在 ObjectListField 的行中包含 2 个文本行。**或任何其他方法或建议,因为我可能是错的,**请指导我它的紧急情况,并且是黑莓的一些新内容发展。

Is it possible to customize Objectfieldlist according to following design?

         ----------------------------
ROW#1    ROW NAME
         row details
         ---------------------------
ROW#2    ROW NAME
         row details
         ---------------------------  
ROW#3    ROW NAME
         row details
         ---------------------------

Row Name will be in bigger font than row details

Basically I need 2 text rows in a Row of ObjectListField.**OR any other method or suggestion as I might be wrong,**pls guide me its urgent and am some what new to Blackberry Development.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤城病女 2024-09-23 09:16:42

ObjectListField 并不是真正执行此操作的正确方法 - 它实际上被设计为 ListField 的快速版本,适合您只需要简单的字符串列表的情况。

您应该扩展 ListField 本身,并提供您自己的 ListFieldCallback 实现,以根据您的数据模型呈现列表。使用 ListField.setCallback 设置回调。

ListFieldCallback.drawListRow 为您提供一个 Graphics 上下文,因此您可以绘制任何您想要的内容,包括多行文本。另请确保在列表字段上调用 ​​ListField.setRowHeight 以使行足够高以容纳 2 行文本(默认高度是字体高度,因此您只能容纳 1 行文本) )。

示例代码类似于(这并不完整,如果没有其他代码就无法编译):

ListField myListField = new ListField();
myListField.setRowHeight(getFont().getHeight() * 2)

myListField.setCallback(new ListFieldCallback() {
    public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) {
       // draw the first line of text
       graphics.drawText(0, y, "ROW " + rowNumber);
       graphics.drawText(20, y, "ROW NAME");
       graphics.drawText(20, y + getFont().getHeight(), "row details"); 
    }

ObjectListField isn't really the right way to do this - it's really designed as a quick version of ListField for those times when you just need a simple list of strings.

You should extend ListField itself, and provide your own implementation of ListFieldCallback that renders your list based on your data model. Use ListField.setCallback to set your callback.

ListFieldCallback.drawListRow gives you a Graphics context, so you can draw whatever you want, including multiple lines of text. Also make sure to call ListField.setRowHeight on your listfield to make the rows high enough for 2 lines of text (the default height is the font height, so you'd only have room for 1 line of text).

Sample code is something like (this is not complete and will not compile without some other code):

ListField myListField = new ListField();
myListField.setRowHeight(getFont().getHeight() * 2)

myListField.setCallback(new ListFieldCallback() {
    public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) {
       // draw the first line of text
       graphics.drawText(0, y, "ROW " + rowNumber);
       graphics.drawText(20, y, "ROW NAME");
       graphics.drawText(20, y + getFont().getHeight(), "row details"); 
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文