Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Hitman47
Posts: 33
Registered: ‎05-14-2010
My Device: Blackberrry Pearl 8320
My Carrier: Unbranded

Understanding ListField - Do I suck or does this class suck?

Ok so basically I have a ListField which contains a manager,

 

1 - Can anybody enlighten me into how the ListField lays out the contents of a field(I assume its a field)? It does not use the normal sublayout.

 

2- In a row I wanna put another Field (piece of info) together with what I already have there. Hint on how could I do that?

 

3- Cant I use a normal Manager (or VFM) to layout a list?

Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Understanding ListField - Do I suck or does this class suck?

ListField is not designed to put a Field in each row. That's not to say that you can't use a Manager to lay out each row; it's just more complicated than you might think.

 

First, be aware that all the rows need to be the same height. (This isn't exactly enforced, but there's no mechanism to do anything else reliably. Many people have tried and failed to come up with something that works on all platforms.)

 

Second, the Manager that represents each row is not added to the ListField. Instead, it is used to manage the drawing of the row from within drawListRow in the ListFieldCallback.

 

One way to do this (adapted from http://pastie.org/282759/wrap) is to subclass the Manager of your choice (or build your own custom manager) and add the following method:

 

public void drawRow(Graphics g, int x, int y, int width, int height) {

// Arrange the cell fields within this row manager.
layout(width, height);

// Place this row manager within its enclosing list.
setPosition(x, y);

// Transformation the graphics so that subpaint paints
// in the right area.
g.pushRegion(getExtent());

// Paint this manager's controlled fields.
subpaint(g);

// Do any other drawing you want for the row (borders, etc.)

// Restore the graphics context.
g.popContext();
}

Then, in the ListFieldCallback, maintain a Vector (or Hashtable, keyed by the row object) of these Manager objects, one for each row. Let's call it "rows". Then implement this callback function:

 

public void drawListRow(ListField listField, Graphics g, int index, int y, int width) {
RowManager rowManager = (RowManager) rows.elementAt(index);
rowManager.drawRow(g, 0, y, width, listField.getRowHeight());
}

That's the essentials, I think.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
Developer
TobiasReaper
Posts: 85
Registered: ‎05-03-2010
My Device: Not Specified

Re: Understanding ListField - Do I suck or does this class suck?

Ah, i know exactly what you need. Have a look at this

 

http://supportforums.blackberry.com/t5/Java-Development/Implement-advanced-buttons-fields-and-manage...

 

In the above given link, you'll find the ListStyleButtonField example, which is essentially a single field on top of another and it gives the impression of a list. A delightfil piece of code by the folks at rim. I assure you that you can add images and any extra information you would want to add.

 

Here's what I was able to do with this class:

 

http://img267.imageshack.us/img267/6100/buttonstylelistfield.jpg

 

Hope it helps.

 

Cheers.

Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Understanding ListField - Do I suck or does this class suck?

That is nice. Thanks for the link, Tobias.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
Contributor
Hitman47
Posts: 33
Registered: ‎05-14-2010
My Device: Blackberrry Pearl 8320
My Carrier: Unbranded

Re: Understanding ListField - Do I suck or does this class suck?

Ok so how does ListField decide the layout of each row (saying it has the info to be drawn)

Like can we do something about it, or it decides on its own, how to draw the text its been given.

Please use plain text.
Developer
TobiasReaper
Posts: 85
Registered: ‎05-03-2010
My Device: Not Specified

Re: Understanding ListField - Do I suck or does this class suck?

Hey Ted,

The pleasure's all mine. Believe you me, I was utterly dissapointed with BlackBerry development before I found this KB article. This article changed everything. Thanks to this article, my BlackBerry app can now give our IPhone app (with its out of this world flashy looking cool GUI) a run for its money.

Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Understanding ListField - Do I suck or does this class suck?

ListField doesn't know anything about the row contents. It just calls ListFieldCallback.drawListRow() for each row that it decides needs rendering. What goes in each row is entirely determined by the ListFieldCallback, which you write.

 

ListField is smart enough to only update rows that are invalid (which, of course, may be all visible rows).




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
Contributor
Hitman47
Posts: 33
Registered: ‎05-14-2010
My Device: Blackberrry Pearl 8320
My Carrier: Unbranded

Re: Understanding ListField - Do I suck or does this class suck?

What I have right now is completely different. I have a drawRow method which is called during my custom paint (which overrides theirs)

 

Thats why Im having it kind of hard to understand what to do. Should I re-do the class from scratch doing it like the sample.

Please use plain text.
Developer
adwiv
Posts: 304
Registered: ‎08-01-2008
My Device: Not Specified

Re: Understanding ListField - Do I suck or does this class suck?

There are few things to remember about ListFields.


1. A listfield is a single Field. It is not a manager comprising of different fields.


2. The focus movement between rows is done by the field itself - just like the focus travels in an editfield.

 

3. The rows of the field are drawn using the drawListRow method. You can override this method to draw individual rows.

 

4. The getFocusRect() method defines the current focus rectangle - generally the selected row. The drawFocus() method uses the the XYRect returned by getFocusRect() to draw its focus.

 

5. You can use the setRowHeight() method to change the height of a single row. This method would change the height of all the rows.

 

6. In most cases, its better to extend the ObjectListField class instead of the ListField class.

 

 

HTH.

Please use plain text.
Developer
ekke
Posts: 1,504
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Understanding ListField - Do I suck or does this class suck?

its some work but you can design nice looking list fields

 

I've written a ListFieldManager which extends a horizontal field manager,

into this I placed a Vertical manager and also a dummi focusable field

(in my case a transparent bitmap)

I need this dummi field to move the list to the left if the list width is > display width

 

the vertical field manager contains:

- a header label

- a ListField as Header: only one line with rounded corners top left and right

and a special background color

- a ListField as Main list field holding the datarows

- a ListField as footer: also only one line with rounded corners bottom left and right

 

I can create lists with/without header/footer, with/without header label

 

the lists can be simple lists or lists with n columns and I draw lines between the columns

there can be special columns like "checkbox" column, the text of all columns can be aligned

left, right, centered - if text is too long I truncate and use Ellipsis

the listlines are colored: each 2nd line has a different color

and the actual selected line another one to see the selected one even if the field doesn't have focus

(all colors same color for header, footer, colored lines with different alpha)

another special column is an "action-column" where a bitmap is drawn

I can define context-menu-Items with scope list or list-row, so dependend from

content of listrow you get other context menus, per ex. if the list has a checkbox

column and the column is checked, the menu knows that this column can be unchecked etc.

 

I have to tune the code - just work-in-progress - and will publish later

 

was a hard work because all has to be done with drawText etc,

but now its easy to use and to configure

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.