开发者

Text wrapping in a ListField row on BlackBerry

开发者 https://www.devze.com 2023-02-02 19:14 出处:网络
How do I wrap text in a ListField row? I am displaying an image on the left and text on the right. Some of the longer text goes out of the Li开发者_高级运维stField row, and I would like it to wrap ins

How do I wrap text in a ListField row? I am displaying an image on the left and text on the right. Some of the longer text goes out of the Li开发者_高级运维stField row, and I would like it to wrap instead of being cut off.


I also face the same problem as my requirement is also same as yours, but in cases where you are not using images, but still want to use a custom label field to pass some parameters you can use my way.

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;
    }
}

to use this custom label field class use setText to set any long text ;

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());

Hope this will help u in some places


Hey I found one more solution to our problem . add image to hfm1 add labelfield to hfm2 now add hfm1 and hfm2 to a vfm now add this vfm to the screen this will act like a label field with image and text and most probably serve our purpose


I found an answer to this question over on the blackberry developer support forums and thought it might be useful to you: http://supportforums.blackberry.com/t5/Java-Development/Can-drawText-wrap-text-into-multiple-lines/m-p/258817#M42493

0

精彩评论

暂无评论...
验证码 换一张
取 消