在BlackBerry上的ListField行中进行文本换行

时间:2011-01-07 09:49:26

标签: java blackberry

如何在ListField行中包装文本?我在左边显示图像,在右边显示文本。一些较长的文本超出ListField行,我希望它包装而不是被截断。

3 个答案:

答案 0 :(得分:2)

我也面临同样的问题,因为我的要求也与你的要求相同,但是如果你没有使用图像,但仍想使用自定义标签字段来传递一些参数,你可以用我的方式。

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.component.LabelField;

public class MyCustomSubscriptionLabelField extends LabelField {

    private Bitmap image = null;
    private String customName = null;
    private String key;
    private String programName, startTime;

    // Edited by vivek on 2010-11-18 to convert Basic Tv as Live tv i.e mapping
    public MyCustomSubscriptionLabelField(String key, String customName,
            long style) {
        super("", FOCUSABLE);
        if (customName == null)
            this.customName = key;
        else
            this.customName = customName;
        this.key = key;
    }

    public MyCustomSubscriptionLabelField(String programName, String startTime,
            String customName, long style) {
        super("", FOCUSABLE);
        this.programName = programName;
        this.startTime = startTime;
    }

    public void setText(String text, int offset, int length) {
        // super.setText(customName, image.getWidth(), customName.length());
        super.setText(text);
    }

    public void paint(Graphics graphics) {

        super.paint(graphics);
    }

    public String getCustomName() {
        return customName;
    }

    public String getKey() {
        return key;
    }

    protected boolean navigationClick(int status, int time) {
        fieldChangeNotify(0);
        return true;
    }

    protected boolean keyChar(char character, int status, int time) {
        if (character == Keypad.KEY_ENTER) {
            fieldChangeNotify(0);
            return true;
        }
        return super.keyChar(character, status, time);
    }

    public void setProgramName(String programName) {
        this.programName = programName;
    }

    public String getProgramName() {
        return programName;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getStartTime() {
        return startTime;
    }
}

使用此自定义标签字段类使用setText设置任何长文本;

customSubscriptionLabelField[j]= 
    new CustomSubscriptionLabelField("","Value tht u want to pass and retrive",style);
customSubscriptionLabelField[j].setText("Any Long text will be wrapped to new line ",0,text.length());

希望这会在某些地方帮助你

答案 1 :(得分:0)

嘿,我找到了另一个解决问题的办法。 将图像添加到hfm1 将labelfield添加到hfm2 现在将hfm1和hfm2添加到vfm 现在将这个vfm添加到屏幕上,这将像带有图像和文本的标签字段,最有可能达到我们的目的

答案 2 :(得分:0)

我在黑莓开发者支持论坛上找到了这个问题的答案,并认为它可能对您有用: http://supportforums.blackberry.com/t5/Java-Development/Can-drawText-wrap-text-into-multiple-lines/m-p/258817#M42493