Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to customize ObjectListField?

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.

like image 422
Ashish Agarwal Avatar asked Mar 02 '26 21:03

Ashish Agarwal


1 Answers

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"); 
    }
like image 101
Anthony Rizk Avatar answered Mar 06 '26 02:03

Anthony Rizk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!