Listfield layout question - blackberry

Posted by Kai on Stack Overflow See other posts from Stack Overflow or by Kai
Published on 2010-05-04T18:29:15Z Indexed on 2010/05/06 3:58 UTC
Read the original article Hit count: 222

Filed under:
|

I'm having an interesting anomaly when displaying a listfield on the blackberry simulator:

The top item is the height of a single line of text (about 12 pixels) while the rest are fine. Does anyone know why only the top item is being drawn this way? Also, when I add an empty venue in position 0, it still displays the first actual venue this way (item in position 1).

Not sure what to do. Thanks for any help.

The layout looks like this:

-----------------------------------
| *part of image* | title         |
-----------------------------------
|                 | title         |
| * full image *  | address       |
|                 | city, zip     |
-----------------------------------

The object is called like so:

listField = new ListField( venueList.size() );
listField.setCallback( this );
listField.setSelectedIndex(-1);
_middle.add( listField );

Here is the drawListRow code:

public void drawListRow( ListField listField, Graphics graphics, int index, int y, int width ) 
{

    listField.setRowHeight(90);
    Hashtable item = (Hashtable) venueList.elementAt( index );

String venue_name = (String) item.get("name");
String image_url = (String) item.get("image_url");
String address = (String) item.get("address");
String city = (String) item.get("city");
String zip = (String) item.get("zip");
EncodedImage img = null;

try 
{
        String filename = image_url.substring( image_url.indexOf("crop/") + 5, image_url.length() );
        FileConnection fconn = (FileConnection) Connector.open( "file:///SDCard/Blackberry/project1/" + filename, Connector.READ);

        if ( !fconn.exists() )
        {

        }
        else
        {
            InputStream input = fconn.openInputStream();

            byte[] data = new byte[(int)fconn.fileSize()];
            input.read(data);
            input.close();
            if(data.length > 0)
            {
                EncodedImage rawimg = EncodedImage.createEncodedImage(data, 0, data.length);

                int dw = Fixed32.toFP(Display.getWidth());
                int iw = Fixed32.toFP(rawimg.getWidth());
                int sf = Fixed32.div(iw, dw);
                img = rawimg.scaleImage32(sf * 4, sf * 4);
            }
            else
            {

            }
        }
}
catch(IOException ef)
{                

} 

   graphics.drawText( venue_name, 140, y, 0, width );
   graphics.drawText( address, 140, y + 15, 0, width );
   graphics.drawText( city + ", " + zip, 140, y + 30, 0, width );
   if(img != null)
   {
       graphics.drawImage(0, y, img.getWidth(), img.getHeight(), img, 0, 0, 0);
   }


}

© Stack Overflow or respective owner

Related posts about blackberry

Related posts about listfield