我想为我的 BB 应用程序制作一个自定义 ListField。我在其中取得了成功。我将在 listField 中绘制两个 RichTextField、一个 Image 和一个 RatingField。
现在的问题是我只想在 LIstField 中显示 RichTextField 的单行。因此,如果有超过一行,那么它应该只显示一个。
我想要它只是因为如果有超过一条线,我的 rattingField 就会重叠。
见下图:
我正在使用下面的代码来创建它并设置值:
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 怎么办??
帮我解决这个问题。