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
Posts: 25
Registered: ‎04-05-2012
My Device: Storm 9630
My Carrier: AT&T

Problem with height of listfield row if there is ony one contact.

Hi,

I have created a listfield to diaplay image and the contact name.

I am facing problem when there is only one contact in the contact list i.e. listfield row dosn't get the specified height to draw only one row.

But it is getting heght properly when there is more then one row to display contacts list.

Please help m out in this.


Thanks.

Developer
Posts: 16,651
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problem with height of listfield row if there is ony one contact.

you can use setRowHeight to specifiy the row height.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 25
Registered: ‎04-05-2012
My Device: Storm 9630
My Carrier: AT&T

Re: Problem with height of listfield row if there is ony one contact.

Thanks,

I have already used it in drawListRow method but no effect. i had set row height as image height i am using in listfield.

Below is the code.

 

public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width)
    {
        
        if(listField == _listField && index < _contacts.size())
        {
           
            Contact item = (Contact)_contacts.elementAt(index);
            String name = getDisplayName(item);
        
            String number = item.getString(BlackBerryContact.TEL, 0).trim();
            
          Bitmap bitm = Bitmap.getBitmapResource("img/ic_contact_picture.png");           
                     
            listField.setRowHeight(bitm.getHeight() + 20);
                   
            int xpos = 5;
            int ypos = 5 + y;
            int w = bitm.getWidth();
            int h = bitm.getHeight();
            Font i = this.getFont().derive(Font.PLAIN);
            final int GREEN_COLOR = 0x639200;
            final int WHITE_COLOR = 0xffffff;
            final int BORDER_COLOR = 0x9c9c9c;
            
           graphics.setColor(BORDER_COLOR);
            graphics.drawLine(0, y, Display.getWidth(), y);
            graphics.setColor(Color.BLACK);
            
            graphics.drawBitmap( xpos, ypos, w, h, bitm, 0, 0 );
            
            xpos = w + 5;
            int fontHeight = this.getFont().getHeight();
            ypos  = (((h + 10) - fontHeight) / 2 ) + y ;
            
            graphics.setFont(i);
            graphics.drawText(name, xpos, ypos);
            
           Border myBorder = BorderFactory.createBitmapBorder(
                    new XYEdges(20, 16, 27, 23),
                    Bitmap.getBitmapResource("border.png"));
            
            Bitmap bitm1 = Bitmap.getBitmapResource("img/expander_ic_minimized.png");
            
             xpos = Display.getWidth() - bitm1.getWidth() - 20 ;
            ypos = (((h + 10) - bitm1.getHeight()) / 2) + y ;

            w = bitm1.getWidth();
            h = bitm1.getHeight();
            
            
            graphics.drawBitmap( xpos, ypos, w, h, bitm1, 0, 0 );
               
        }
    }

 

 

But for single row it doesn't effect and when i add more contacts listfield height adjusted auto matically as i defined.

 

Please let me know where m going wrong in this code.

 

Thanks.

Developer
Posts: 16,651
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problem with height of listfield row if there is ony one contact.

don't use setRowHeight inside of drawListRow, it is a global value.
getBitmapResource is also better called outside of the method, especially as you use the same picture over and over. same with the final variables.
why do you create a border?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter