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
Highlighted
Developer
Posts: 109
Registered: ‎08-21-2012
My Device: Blackberry curve
My Carrier: company
Accepted Solution

custom listfield

I adding image in my listfield and defined  tha paint method for the bitmap field. Inside the bitmapfield i am using thread to download the image and set the image to bitmapfield.  Now when i am scrolling ,list came in focus then downloading stats but when it completes until i move my cursor the image is not coming to the screen. Means the list image will dispaly on when i move my cursor.

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

Re: custom listfield

a listfield does not display bitmapfields, it controls the paint using drawListRow.
you can invalidate a list row when the picture for it arrives.
----------------------------------------------------------
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
Developer
Posts: 109
Registered: ‎08-21-2012
My Device: Blackberry curve
My Carrier: company

Re: custom listfield

i am using drawlistrow as you told ...but what happening is when i am scrolling and stoping my scroll the list will start downloading image and the update the image.it is doing too...the problem is i can see the updated image only when i do some curser movement.

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

Re: custom listfield

and do you invalidate the listrow that contains the image after downloading it?
----------------------------------------------------------
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
Developer
Posts: 109
Registered: ‎08-21-2012
My Device: Blackberry curve
My Carrier: company

Re: custom listfield

Thankyou for your response. i tried your suggestion but still the problem persists.i think i am keeping the invalidate() in wrong place.

I am send my custome list field code. Tell me after downloading from url i am changing the image,then after that what i  have write so that the image will display in screen.

 

 

class TaskListField extends ListField implements ListFieldCallback {
     private Vector rows;
     private Bitmap p1;
     private Bitmap p2;
     private Bitmap p3;
     final int k;
     BitmapField bt=null;
     final String url;
     public Graphics graphics1;
     public TaskListField(Bitmap img,int i,String url1) {
     super(0, ListField.MULTI_SELECT);
     k=i;

      url=url1;
      setRowHeight(150);
      setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);
      setCallback(this);

        Bitmap bitmapScaled3 = new Bitmap(149,133);
          img.scaleInto(bitmapScaled3 , Bitmap.FILTER_LANCZOS);
          rows = new Vector();
          int x=0;
          TableRowManager row = new TableRowManager();
          
        bt=new  BitmapField(bitmapScaled3,Field.FOCUSABLE){
      
        private boolean hasFocus = false;  
      
        public  void onFocus(int direction){  
        super.onFocus(direction);
        hasFocus = true;
        invalidate();
        }  
      
        public void onUnfocus()   
        {    
            super.onUnfocus();
            hasFocus = false;  
            invalidate();
        }  
     
       
        public void paint(Graphics graphics)   
       {

        graphics1=graphics;
        Thread threadToRun = new Thread() {
            public void run() {

              int width = Display.getWidth();  
         
              XYRect redrawRect = graphics1.getClippingRect();
              if(DirectoryScreen_Land.imgcount[k]==1){
                    DirectoryScreen_Land.imgcount[k]=0;
                    DownloadImage di=new DownloadImage();
                    Bitmap img=null;
                    try {
                        img=di.downloadBarCode(url);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                
                Bitmap bitmapScaled = new Bitmap(150,110);
                img.scaleInto(bitmapScaled , Bitmap.FILTER_LANCZOS,Bitmap.SCALE_TO_FIT);
                setBitmap(bitmapScaled);
                }
           
    
       }};threadToRun.start();
       super.paint(graphics);  
              
       }  
};
        row.add(bt);
        rows.addElement(row);
        setSize(rows.size());

 }
    

     // ListFieldCallback Implementation
     public void drawListRow(ListField listField, Graphics g, int index, int y,
       int width) {
      TaskListField list = (TaskListField) listField;
      TableRowManager rowManager = (TableRowManager) list.rows
        .elementAt(index);
      rowManager.drawRow(g, 0, y, width, list.getRowHeight());
     }

     private class TableRowManager extends Manager {
      public TableRowManager() {
       super(0);
      }

      // Causes the fields within this row manager to be layed out then
      // painted.
      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);

       // Apply a translating/clipping transformation to the graphics
       // context so that this row paints in the right area.
       g.pushRegion(getExtent());

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

       // Restore the graphics context.
       g.popContext();
      }
      
      protected void sublayout(int width, int height) {

       int fontHeight = Font.getDefault().getHeight();
       int preferredWidth = getPreferredWidth();

       // start with the Bitmap Field of the priority icon
       Field field = getField(0);
       layoutChild(field, 150,110);
       setPositionChild(field, 0, 0);
       setExtent(preferredWidth, getPreferredHeight());
      }

    
      public int getPreferredWidth() {
       return Graphics.getScreenWidth();
      }

      public int getPreferredHeight() {
       return getRowHeight();
      }
     }

     public Object get(ListField listField, int index) {
      // TODO Auto-generated method stub
      return null;
     }

     public int getPreferredWidth(ListField listField) {
      // TODO Auto-generated method stub
      return 0;
     }

     public int indexOfList(ListField listField, String prefix, int start) {
      // TODO Auto-generated method stub
      return 0;
     }

    }

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

Re: custom listfield

overwriting paint is not the correct way to use a listfield.
take a look at some of the listfield samples, like
http://supportforums.blackberry.com/t5/Java-Development/Create-a-colour-ListField/ta-p/442955
to see how to correctly use a listfield.

Your current implementation is quite a mess.
----------------------------------------------------------
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
Developer
Posts: 109
Registered: ‎08-21-2012
My Device: Blackberry curve
My Carrier: company

Re: custom listfield

now i define the paint method for my list...like this

 

class TaskListField extends ListField implements ListFieldCallback {
     private Vector rows;
     private Bitmap p1;
     private Bitmap p2;
     private Bitmap p3;
     final int k;
     BitmapField bt=null;
     final String url;
     public Graphics graphics1;
 
     public TaskListField(Bitmap img,int i,String url1) {
     super(0, ListField.MULTI_SELECT);
     k=i;

      url=url1;
      setRowHeight(150);
      setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);
      setCallback(this);

        Bitmap bitmapScaled3 = new Bitmap(149,133);
          img.scaleInto(bitmapScaled3 , Bitmap.FILTER_LANCZOS);
          rows = new Vector();
          int x=0;
          TableRowManager row = new TableRowManager();
          
        bt=new  BitmapField(bitmapScaled3,Field.FOCUSABLE);

        row.add(bt);
        rows.addElement(row);
        setSize(rows.size());
        

   }

     public void paint(Graphics graphics)   
     {

      graphics1=graphics;
         Thread threadToRun = new Thread() {
          public void run() {
//              UiApplication.getUiApplication().invokeLater(new Runnable() {
//                    public void run() {
            int width = Display.getWidth();  
       
            XYRect redrawRect = graphics1.getClippingRect();
           if(DirectoryScreen_Land.imgcount[k]==1){
                    DirectoryScreen_Land.imgcount[k]=0;
                    DownloadImage di=new DownloadImage();
                    Bitmap img=null;
                    
                try {
                    img=di.downloadBarCode(url);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                Bitmap bitmapScaled = new Bitmap(150,110);
                img.scaleInto(bitmapScaled , Bitmap.FILTER_LANCZOS,Bitmap.SCALE_TO_FIT);
                bt.setBitmap(bitmapScaled);
                
        
            //    drawListRow(new TaskListField(bitmapScaled,k, url),graphics1,0,0,100);
                //setCallback(new TaskListField(bitmapScaled,0,url));
                }
        
            //        }});
     }};threadToRun.start();
    
    
     
     super.paint(graphics);  
            
     }  

     // ListFieldCallback Implementation
     public void drawListRow(ListField listField, Graphics g, int index, int y,
       int width) {
      TaskListField list = (TaskListField) listField;
      TableRowManager rowManager = (TableRowManager) list.rows
        .elementAt(index);
      rowManager.drawRow(g, 0, y, width, list.getRowHeight());
     }

     private class TableRowManager extends Manager {
      public TableRowManager() {
       super(0);
      }

      // Causes the fields within this row manager to be layed out then
      // painted.
      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);

       // Apply a translating/clipping transformation to the graphics
       // context so that this row paints in the right area.
       g.pushRegion(getExtent());

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

       // Restore the graphics context.
       g.popContext();
      }
      
      protected void sublayout(int width, int height) {

       int fontHeight = Font.getDefault().getHeight();
       int preferredWidth = getPreferredWidth();

       // start with the Bitmap Field of the priority icon
       Field field = getField(0);
       layoutChild(field, 150,110);
       setPositionChild(field, 0, 0);
      
       setExtent(preferredWidth, getPreferredHeight());
      }

    
      public int getPreferredWidth() {
       return Graphics.getScreenWidth();
      }

      public int getPreferredHeight() {
       return getRowHeight();
      }
     }

     public Object get(ListField listField, int index) {
      // TODO Auto-generated method stub
      return null;
     }

     public int getPreferredWidth(ListField listField) {
      // TODO Auto-generated method stub
      return 0;
     }

     public int indexOfList(ListField listField, String prefix, int start) {
      // TODO Auto-generated method stub
      return 0;
     }

    }

 

i am calling this list in my screen as follows:

TaskListField t=new TaskListField(img,i,url);// kept insid the loop where with this manager some other manager //are also theire

manager.add(t);

 

 

now tell me how to change the image of bitmapfield

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

Re: custom listfield

for a listfield, you don't overwrite paint, you overwrite drawListRow.
Otherwise there is no sense in using listfield at all.
----------------------------------------------------------
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
Developer
Posts: 109
Registered: ‎08-21-2012
My Device: Blackberry curve
My Carrier: company

Re: custom listfield

Ok .then can i place my thread inside the drawlistRow  () and  change the bitmap image after loading from url

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

Re: custom listfield

try to get a clear image of the control flow.
starting a thread in drawListRow is not a good idea.
----------------------------------------------------------
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