带有单行的BlackBerry RichTextField

时间:2012-12-19 11:10:40

标签: blackberry textfield blackberry-simulator

我想为我的BB应用程序制作一个自定义ListField。我成功了。我将把两个RichTextField,一个Image和一个RatingField绘制到listField中。

现在问题是我只想在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?

帮助我。

1 个答案:

答案 0 :(得分:0)

您需要使用RichTextField的layout方法来设置 RichTextField 的可用空间量。