2012-12-19 56 views
0

我想爲我的BB應用程序做一個自定義的ListField。我獲得了成功。我將把兩個RichTextField,一個Image和一個RatingField繪製到listField中。黑莓RichTextField單線

現在的問題是我只想在LIstField中顯示RichTextField的單行。所以如果有多條線,那麼它應該只顯示一條線。

我想要它只是因爲我的rattingField越來越重疊,如果有更多的一行。

見下圖:

enter image description here

我使用下面的代碼來創建它並將其值設置:

rows = new TableRowManager[dealArray.length()]; 

     rating2 = new RatingField(Bitmap.getBitmapResource("yellow_star.png") 
       , Bitmap.getBitmapResource("white_star.png") 
       , Bitmap.getBitmapResource("yellow_star.png") 
       , Bitmap.getBitmapResource("white_star.png") 
       , 8, 5, Field.FIELD_HCENTER); 
     try{ 
      System.out.println("================== = = ==HERE IT IS COMES"); 

     for(int i=0;i<dealArray.length();i++){ 
      // create a table row manager 
      rows[i] = new TableRowManager(); 
      // set the menu item name 
      EncodedImage encoded_img=EncodedImage.getEncodedImageResource("no_photo.png"); 
      byte[] data=encoded_img.getData(); 
      Bitmap bitmap=Bitmap.createBitmapFromBytes(data, 0, data.length,1);//Here we get the Image; 
      Bitmap scaleBitmap=new Bitmap(100,100);//Now we are scaling that image; 
      bitmap.scaleInto(scaleBitmap, Bitmap.FILTER_LANCZOS); 


      rows[i].add(new BitmapField(scaleBitmap)); 

      rows[i].add(new RichTextField(dealArray.getJSONObject(i).getString("DealName"), DrawStyle.ELLIPSIS)); 

      rows[i].add(new RichTextField(dealArray.getJSONObject(i).getString("DealDescription"), TextField.NO_NEWLINE)); 

      rows[i].add(new RatingField(Bitmap.getBitmapResource("yellow_star.png") 
        , Bitmap.getBitmapResource("white_star.png") 
        , Bitmap.getBitmapResource("yellow_star.png") 
        , Bitmap.getBitmapResource("white_star.png") 
        , Integer.parseInt(dealArray.getJSONObject(i).getString("DealTotalStamp")) 
        , Integer.parseInt(dealArray.getJSONObject(i).getString("StampCompletionOnDeal")) 
        , Field.FIELD_HCENTER)); 
      // create a table row manager 

     } 
     }catch(Exception e){ 
      e.printStackTrace(); 
     } 

     System.out.println("HELLOOOOoo oo ooo"); 

     vfm.addAll(rows); 

,並提請它drawListRow,我用下面的代碼:

private class TableRowManager extends Manager{ 
      public TableRowManager(){ 
       super(0); 
      } 
      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); 

       g.setColor(0x00000000); 
       // g.drawLine(0, 0, getPreferredWidth(), 0); 

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

      protected void sublayout(int width, int height) { 
       // TODO Auto-generated method stub 
       int preferredWidth = getPreferredWidth(); 
       int preferredHeight = getPreferredHeight(); 
       // for deal image 


       //SBitmapField bmp = new BitmapField(Bitmap.getBitmapResource("")); 
       Field field = getField(0); 
       layoutChild(field, 100, 100); 
       setPositionChild(field, 5, 5); 

       // for deal name 
       field = getField(1); 
       layoutChild(field, preferredWidth - 100, 0); 
       setPositionChild(field, 110, 0); 

       // for deal Description 
       field = getField(2); 
       layoutChild(field, preferredWidth, 5); 
       setPositionChild(field,110 , 35); 

       // for Deal stamp 
       field = getField(3); 
       layoutChild(field, preferredWidth, 50); 
       setPositionChild(field, 110, 65); 


       setExtent(preferredWidth, 110); 
      } 
      public int getPreferredWidth() 
      { 
       return Graphics.getScreenWidth(); 
      } 

      // The preferred height of a row is the "row height" as defined in the 
      // enclosing list. 
      public int getPreferredHeight() 
      { 
       return 30; 
      } 
     } 

現在該怎麼辦,如果我想要的描述RichTextField在強制t單線?

幫我這個。

回答

0

您需要使用RichTextField的layout方法來設置可用空間量爲RichTextField