Search code examples
imageblackberrylistfield

Blackberry Listfield with Live Image


I want to display a listfield with live image in all rows of the listfield


Solution

  • check out this

    also use the following code for displaying live images:

    public static String getImageFromUrl(String url) {
                //Image img = null;
                String imageData = null;
                try
                {            
                  imageData = getDataFromUrl(url);
                  //img = Image.createImage(imageData.getBytes(), 0,imageData.length() );          
                }
                catch(Exception e1) {
                    e1.printStackTrace();
                }
    
                return imageData;
            }
    
            public static String getDataFromUrl(String url) 
                  throws IOException {
    
                StringBuffer b = new StringBuffer();
                InputStream is = null;
                HttpConnection c = null;
    
                long len = 0 ;
                int ch = 0;
    
                ConnectionFactory connFact = new ConnectionFactory();
                  ConnectionDescriptor connDesc;
                  connDesc = connFact.getConnection(url);
    
                  if (connDesc != null)
                  {
                      //HttpConnection httpConn;
                      c = (HttpConnection)connDesc.getConnection();
                  }
    
               // c = (HttpConnection)Connector.open(url);
                is = c.openInputStream();
                len = c.getLength();
                if( len != -1) {
                    // Read exactly Content-Length bytes
                    for(int i =0 ; i < len ; i++ )
                        if((ch = is.read()) != -1) {
                        b.append((char) ch);
                        }
                } else {
                    //Read until the connection is closed.
                    while ((ch = is.read()) != -1) {
                        len = is.available() ;
                        b.append((char)ch);
                    }
                }
    
                is.close();
                c.close();
                return b.toString();
            }  
    

    Hope this will help you.