黑莓列表字段开发

发布于 2024-12-04 23:42:11 字数 52 浏览 0 评论 0原文

任何人都可以建议我如何在黑莓中创建一个可点击的列表字段,以便单击一项时必须出现一个新屏幕。

Can anybody suggest me how to create a clickable list field in blackberry such that on clicking one item a new screen must appear.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幼儿园老大 2024-12-11 23:42:11

我在 JDE 5.0 上使用 VerticalFieldManager 和自定义扩展字段完成了类似的工作。

我假设您有一个想要在主屏幕上显示的对象列表。

第一的;创建一个为列表项扩展 Field 的类,根据您的要求重写其绘制方法、布局方法和其他事件。

接下来,创建一个您想要显示列表的主屏幕。填充对象列表后,在循环中将每个对象模型传递给先前创建的字段的构造函数。然后将fieldChanged事件添加到该字段并将其添加到verticalFieldManager。

当您想要单击事件并在另一个屏幕上显示其详细信息时,您需要覆盖事件(例如 fieldChanged 事件)。

最后,创建一个详细信息屏幕,它采用所需的参数来显示列表项的对象详细信息。在主屏幕实现的 fieldChanged 事件中,将对象传递到详细信息屏幕并推送详细信息屏幕。

另外,方法可能对您有用。

示例:

自定义字段:

public class CListItemField extends Field {

    private CListItemModel model;

    public CListItemField(CListItemModel _model, long style) {
        super(style);
        this.model = _model;
    }

    public CListItemModel getModel() {
        return this.model;
    }

    // overrides

    public int getPreferredHeight() {
        //return custom height
    }

    public int getPreferredWidth() {
        //return custom width
    }

    protected void layout(int width, int height) {
        setExtent(Math.min(width, getPreferredWidth()), getPreferredHeight());
    }

    protected void paint(Graphics g) {

        //custom paint stuff (borders, fontstyle, text position, icons etc.)

        if (isFocus()) {
            //focused item display settings

        } else {
            //item display settings
        }

    }

    protected void drawFocus(Graphics graphics, boolean on) {
    }

    public boolean isFocusable() {
        return true;
    }

    protected void onFocus(int direction) {
        super.onFocus(direction);
        invalidate();
    }

    protected void onUnfocus() {
        super.onUnfocus();
        invalidate();
    }

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

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

}

列表屏幕:

public class ScreenListbox extends MainScreen implements FieldChangeListener, FocusChangeListener {

private VerticalFieldManager verticalField;
private Vector listItemVector;

public ScreenOttoInbox(String title) {
    super(title, Manager.NO_VERTICAL_SCROLL);
    setData();
    setComponents();
}

private void setData() {
    //populate listItemVector according to your business (ie. read json response then parse it and collect it to a vector)
}

public void setComponents() {
    verticalField = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
    setListContent(verticalField, listItemVector);
    add(verticalField);
}

private void setListContent(VerticalFieldManager field, Vector vector) {
    try {
        int vlen = vector.size();
        for (int i = 0; i < vlen; i++) {
            CListItemModel model = (CListItemModel) vector.elementAt(i);
            CListItemField itemField = new CListItemField(model, Field.FOCUSABLE | Field.ACTION_INVOKE);
            itemField.setChangeListener(this);
            itemField.setFocusListener(this);
            field.add(itemField);
        }
    } catch (Exception ex) { }
}

protected boolean onSavePrompt() {
    return true;
}

public void fieldChanged(Field field, int context) {
    //custom field's click/touch event handler
    CListItemField itemField = (CListItemField) field;
    ScreenItemDetail scrDetail = new ScreenItemDetail(itemField.getModel());
    ScreenUtil.pushScreenWithLoader(scrDetail,true);
}

protected void onDisplay() {
    super.onDisplay();
}
 }

I've done a similar work with VerticalFieldManager and custom extended Field on JDE 5.0.

I assume that you have a list of objects that you wanted to display on main screen.

First; create a class which extends Field for your list's item, override its paint method, layout method and otuher events as your requirements.

Next, create a main screen that you wanted to show the list. Once you have populated your object list, in a loop, pass each object model to previously created field's constructor. Then add fieldChanged event to that field and add it to verticalFieldManager.

You need to override the events (like fieldChanged event) as you want to click on it and display its detail on another screen.

Finally, create a detail screen that takes required arguments to display your list item's object detail. On fieldChanged event of your main screen implementation, pass your object to detail screen and push the detail screen.

Also, this approach may be useful for you.

Example:

custom field:

public class CListItemField extends Field {

    private CListItemModel model;

    public CListItemField(CListItemModel _model, long style) {
        super(style);
        this.model = _model;
    }

    public CListItemModel getModel() {
        return this.model;
    }

    // overrides

    public int getPreferredHeight() {
        //return custom height
    }

    public int getPreferredWidth() {
        //return custom width
    }

    protected void layout(int width, int height) {
        setExtent(Math.min(width, getPreferredWidth()), getPreferredHeight());
    }

    protected void paint(Graphics g) {

        //custom paint stuff (borders, fontstyle, text position, icons etc.)

        if (isFocus()) {
            //focused item display settings

        } else {
            //item display settings
        }

    }

    protected void drawFocus(Graphics graphics, boolean on) {
    }

    public boolean isFocusable() {
        return true;
    }

    protected void onFocus(int direction) {
        super.onFocus(direction);
        invalidate();
    }

    protected void onUnfocus() {
        super.onUnfocus();
        invalidate();
    }

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

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

}

list screen:

public class ScreenListbox extends MainScreen implements FieldChangeListener, FocusChangeListener {

private VerticalFieldManager verticalField;
private Vector listItemVector;

public ScreenOttoInbox(String title) {
    super(title, Manager.NO_VERTICAL_SCROLL);
    setData();
    setComponents();
}

private void setData() {
    //populate listItemVector according to your business (ie. read json response then parse it and collect it to a vector)
}

public void setComponents() {
    verticalField = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
    setListContent(verticalField, listItemVector);
    add(verticalField);
}

private void setListContent(VerticalFieldManager field, Vector vector) {
    try {
        int vlen = vector.size();
        for (int i = 0; i < vlen; i++) {
            CListItemModel model = (CListItemModel) vector.elementAt(i);
            CListItemField itemField = new CListItemField(model, Field.FOCUSABLE | Field.ACTION_INVOKE);
            itemField.setChangeListener(this);
            itemField.setFocusListener(this);
            field.add(itemField);
        }
    } catch (Exception ex) { }
}

protected boolean onSavePrompt() {
    return true;
}

public void fieldChanged(Field field, int context) {
    //custom field's click/touch event handler
    CListItemField itemField = (CListItemField) field;
    ScreenItemDetail scrDetail = new ScreenItemDetail(itemField.getModel());
    ScreenUtil.pushScreenWithLoader(scrDetail,true);
}

protected void onDisplay() {
    super.onDisplay();
}
 }
糖果控 2024-12-11 23:42:11

创建一个如下所示的类。

 import java.util.Vector;
    import net.rim.device.api.collection.util.SparseList;
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.component.ListField;
    import net.rim.device.api.ui.component.ListFieldCallback;

    public class CListCallback  implements ListFieldCallback {
    private String[] resource;
    private int rgb=Color.BLACK;
    Vector elements;
    Bitmap arraow;
    public CListCallback(String[] resources){
        this.resource=resources;

    }
        public void drawListRow(ListField listField, Graphics graphics, int index,
                int y, int width) {

           String text=(String) get(listField, index);
            graphics.setColor(rgb);
            graphics.drawText(text,60,y+25);  
             graphics.drawLine(0, y+59, DConfig.disWidth, y+59);

        }
      public Object get(ListField listField, int index) {

            return resource[index];
        }
   public int getPreferredWidth(ListField listField) {

             return DConfig.disWidth+10;
        }
    public int indexOfList(ListField listField, String prefix, int start) {

            return -1;
        }

    }

并在 MainScreen 类中使用上面的类。

CListCallback clmenu=new CListCallback(arrayitems);
      final ListField lf = new ListField(arraymenu.length) {
            protected boolean keyChar(char character, int status, int time) {
                if (character == Keypad.KEY_ENTER) {
                    fieldChangeNotify(0);
                    return true;
                }
                return super.keyChar(character, status, time);
            }

            protected boolean navigationUnclick(int status, int time) {
                fieldChangeNotify(0);
                return true;
            }
        };
        lf.setCallback(clmenu);
        lf.setRowHeight(60);
        lf.setChangeListener(new FieldChangeListener() {

            public void fieldChanged(Field field, int context) 
            {
            int index=lf.getSelectedIndex();
                                 UiApplication.getUiApplication.pushScreen(newNewScreen(imgarray[index]));  
            }
        });
        add(lf);    

就是这样,它会起作用

Create a class like below.

 import java.util.Vector;
    import net.rim.device.api.collection.util.SparseList;
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.component.ListField;
    import net.rim.device.api.ui.component.ListFieldCallback;

    public class CListCallback  implements ListFieldCallback {
    private String[] resource;
    private int rgb=Color.BLACK;
    Vector elements;
    Bitmap arraow;
    public CListCallback(String[] resources){
        this.resource=resources;

    }
        public void drawListRow(ListField listField, Graphics graphics, int index,
                int y, int width) {

           String text=(String) get(listField, index);
            graphics.setColor(rgb);
            graphics.drawText(text,60,y+25);  
             graphics.drawLine(0, y+59, DConfig.disWidth, y+59);

        }
      public Object get(ListField listField, int index) {

            return resource[index];
        }
   public int getPreferredWidth(ListField listField) {

             return DConfig.disWidth+10;
        }
    public int indexOfList(ListField listField, String prefix, int start) {

            return -1;
        }

    }

And use above class in MainScreen class.

CListCallback clmenu=new CListCallback(arrayitems);
      final ListField lf = new ListField(arraymenu.length) {
            protected boolean keyChar(char character, int status, int time) {
                if (character == Keypad.KEY_ENTER) {
                    fieldChangeNotify(0);
                    return true;
                }
                return super.keyChar(character, status, time);
            }

            protected boolean navigationUnclick(int status, int time) {
                fieldChangeNotify(0);
                return true;
            }
        };
        lf.setCallback(clmenu);
        lf.setRowHeight(60);
        lf.setChangeListener(new FieldChangeListener() {

            public void fieldChanged(Field field, int context) 
            {
            int index=lf.getSelectedIndex();
                                 UiApplication.getUiApplication.pushScreen(newNewScreen(imgarray[index]));  
            }
        });
        add(lf);    

Thats it.it will work

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文