将按钮添加到 BlackBerry 中的 ListField

发布于 2024-10-02 06:45:49 字数 298 浏览 1 评论 0原文

我正在使用 ListField 在黑莓手机中,想要在行中包含一个带有两个文本字段的按钮,例如:

           Button
           Text1
           Text2  

但我无法添加按钮。我找到的所有帮助都是关于添加图像的。

I am using a ListField in BlackBerry and want to include a button with two text fields in the row like:

           Button
           Text1
           Text2  

But I am not able to add the buttons. All the help I've found is about adding images.

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

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

发布评论

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

评论(3

滥情稳全场 2024-10-09 06:45:49

默认情况下...列表字段将焦点集中在整个单行上...而不是一行上的单个字段(正如您所说,您要添加三个字段...按钮、文本字段、文本字段)。

所以我想知道为什么你想在一行中添加按钮和两个单独的文本字段...我认为如果你想只关注按钮或只关注文本字段这并不容易...在列表字段的单行中。

顺便说一句...这是示例代码........您如何在单行列表字段中创建三个字段...

只需在主屏幕的类中调用此列表字段类的构造函数即可添加它就像...

DetailListField _listField = new DetailListField();
add(_listField); 

DetailListField 类 -

class DetailListField extends ListField implements ListFieldCallback
{
    private Vector rows;
    private Font font;

    public DetailListField()
    {
        this(0, ListField.USE_ALL_WIDTH | DrawStyle.LEFT);
    }

    public DetailListField(int numRows, long style)
    {
        super(0, style);

        try
        {
            rows = new Vector();
            font = Font.getDefault().derive(Font.PLAIN, 7, Ui.UNITS_pt);

            setRowHeight(-2);                       
            setCallback(this);

            for (int x = 0 ; x < 5 ; x++)
            {
                TableRowManager row = new TableRowManager();

                // button, textfield, textfield
                ButtonField _btn = new ButtonField("Button", ButtonField.CONSUME_CLICK);
                _btn.setBorder(VISUAL_STATE_NORMAL, BorderFactory.createSimpleBorder(new XYEdges(1,1,1,1),
                        new XYEdges(0x557788, 0xAA22BB, 0x557788, 0xAA22BB),
                        Border.STYLE_SOLID));
                row.add(_btn);

                BasicEditField _basicEdit1 = new BasicEditField(BasicEditField.EDITABLE | BasicEditField.FILTER_DEFAULT);
                _basicEdit1.setBorder(VISUAL_STATE_NORMAL, BorderFactory.createSimpleBorder(new XYEdges(2,2,2,2),
                        new XYEdges(0x557788, 0xAA22BB, 0x557788, 0xAA22BB),
                        Border.STYLE_SOLID));
                row.add(_basicEdit1);

                BasicEditField _basicEdit2 = new BasicEditField(BasicEditField.EDITABLE | BasicEditField.FILTER_DEFAULT);
                _basicEdit2.setBorder(VISUAL_STATE_NORMAL, BorderFactory.createSimpleBorder(new XYEdges(2,2,2,2),
                        new XYEdges(0x994422, 0xAA22BB, 0x994422, 0xAA22BB),
                        Border.STYLE_SOLID));
                row.add(_basicEdit2);


                // add id to the vector.
                rows.addElement(row); // returnData[x][0]);

                // call draw list row
                // then call constructor of manager class
            } 

            setSize(rows.size());
            invalidate();
        } catch(Exception e) {
        }
    }

    public void drawListRow(ListField list, Graphics g, int index, int y, int width)
    {
        try
        {
            DetailListField dl = (DetailListField)list;
            TableRowManager rowManager = (TableRowManager)dl.rows.elementAt(index);
            rowManager.drawRow(g, 0, y, width, list.getRowHeight());

        } catch(Exception e) {
        }
    }   

    protected boolean keyChar(char key, int status, int time)
    {   
        if (key == Characters.ENTER)
        {
            return true;
            // We've consumed the event.    
        }
        else if(key == Characters.ESCAPE)
        {
            return true;
        }             
        return super.keyChar(key, status, time);
    }

    protected boolean navigationClick(int status, int time)
    {
        try
        {
            // use below method if want to get label value from manager.
            final int index = this.getSelectedIndex();

            if(index >= 0) {
                UiApplication.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        Dialog.alert("Selected index number : " + (index + 1));
                    }
                });
            }
        } catch (final Exception e) {
        }
        return true;   
    }

     public Object get(ListField listField, int index)
     {
         // TODO Auto-generated method stub
         return rows.elementAt(index);
     }

     public int getPreferredWidth(ListField listField)
     {
         // TODO Auto-generated method stub
         return 0;
     }

     public int indexOfList(ListField listField, String prefix, int start)
     {
         // TODO Auto-generated method stub
         return rows.indexOf(prefix, start);
     }


    /**
     *  MANAGER CLASS  
     */
    private class TableRowManager extends Manager
    {
        int _height = 0, _width = 0;
        int yPos = 0;

        public TableRowManager()
        {
            super(0);
        }

        // Causes the fields within this row manager to be layed out then
        // painted.
        public void drawRow(Graphics g, int x, int y, int width, int height)
        {
            try
            {
                _height = height;
                _width = getPreferredWidth();

                yPos = y;

                // Arrange the cell fields within this row manager.
                // set the size and position of each field.
                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(0x00CACACA);
                g.drawLine(0, 0, getPreferredWidth(), 0);

                // Restore the graphics context.
                g.popContext();
            } catch(Exception e) {
                System.out.println("Exeception : (DetailListField) 4 : " + e.toString());
            }
        }

        // Arranges this manager's controlled fields from left to right within
        // the enclosing table's columns.
        protected void sublayout(int width, int height)
        {
            try
            {

                // set the bitmap field
                Field _field0 = getField(0);
                layoutChild(_field0, (_width/3) - 30 , _height - 20);
                setPositionChild(_field0, 2, 5);

                // set the name field
                Field _field1 = getField(1);
                _field1.setFont(font);
                layoutChild(_field1, (_width/3) - 30, _field1.getPreferredHeight());
                setPositionChild(_field1, (_width/3) - 30 + 10, 5);

                Field _field2 = getField(2);
                _field2.setFont(font);              
                layoutChild(_field2, (_width/3) - 30, _field2.getPreferredHeight());
                setPositionChild(_field2, ((_width/3) - 30)*2 + 20, 5);


                setExtent(_width, _height);

            } catch(Exception e) {
                System.out.println("Exeception : (DetailListField) 5 : " + e.toString());
            }
        }
        // The preferred width of a row is defined by the list renderer.
        public int getPreferredWidth()
        {
            return (Display.getWidth());
        }
        // The preferred height of a row is the "row height" as defined in the
        // enclosing list.
        public int getPreferredHeight()
        {
            return _height;
        }       
    }
}

bt 我仍然不知道如何关注单行的单个字段...

by default ... list field provides the focus on a single row as a whole....and not to the single field on a row(as u told that u want to add three fields....buttons, textfield, textfield).

so i want to know why do u want to add buttons and two separate text-fields in a single row... I think its not easy if u want to get focus only on button OR only on a text-field....in a single row of a list field.

by the way... here is the sample code........ how u create three fields in a single row of list field...

just call the constructor of this list-field class in ur main screen's class and add it like.....

DetailListField _listField = new DetailListField();
add(_listField); 

DetailListField class -

class DetailListField extends ListField implements ListFieldCallback
{
    private Vector rows;
    private Font font;

    public DetailListField()
    {
        this(0, ListField.USE_ALL_WIDTH | DrawStyle.LEFT);
    }

    public DetailListField(int numRows, long style)
    {
        super(0, style);

        try
        {
            rows = new Vector();
            font = Font.getDefault().derive(Font.PLAIN, 7, Ui.UNITS_pt);

            setRowHeight(-2);                       
            setCallback(this);

            for (int x = 0 ; x < 5 ; x++)
            {
                TableRowManager row = new TableRowManager();

                // button, textfield, textfield
                ButtonField _btn = new ButtonField("Button", ButtonField.CONSUME_CLICK);
                _btn.setBorder(VISUAL_STATE_NORMAL, BorderFactory.createSimpleBorder(new XYEdges(1,1,1,1),
                        new XYEdges(0x557788, 0xAA22BB, 0x557788, 0xAA22BB),
                        Border.STYLE_SOLID));
                row.add(_btn);

                BasicEditField _basicEdit1 = new BasicEditField(BasicEditField.EDITABLE | BasicEditField.FILTER_DEFAULT);
                _basicEdit1.setBorder(VISUAL_STATE_NORMAL, BorderFactory.createSimpleBorder(new XYEdges(2,2,2,2),
                        new XYEdges(0x557788, 0xAA22BB, 0x557788, 0xAA22BB),
                        Border.STYLE_SOLID));
                row.add(_basicEdit1);

                BasicEditField _basicEdit2 = new BasicEditField(BasicEditField.EDITABLE | BasicEditField.FILTER_DEFAULT);
                _basicEdit2.setBorder(VISUAL_STATE_NORMAL, BorderFactory.createSimpleBorder(new XYEdges(2,2,2,2),
                        new XYEdges(0x994422, 0xAA22BB, 0x994422, 0xAA22BB),
                        Border.STYLE_SOLID));
                row.add(_basicEdit2);


                // add id to the vector.
                rows.addElement(row); // returnData[x][0]);

                // call draw list row
                // then call constructor of manager class
            } 

            setSize(rows.size());
            invalidate();
        } catch(Exception e) {
        }
    }

    public void drawListRow(ListField list, Graphics g, int index, int y, int width)
    {
        try
        {
            DetailListField dl = (DetailListField)list;
            TableRowManager rowManager = (TableRowManager)dl.rows.elementAt(index);
            rowManager.drawRow(g, 0, y, width, list.getRowHeight());

        } catch(Exception e) {
        }
    }   

    protected boolean keyChar(char key, int status, int time)
    {   
        if (key == Characters.ENTER)
        {
            return true;
            // We've consumed the event.    
        }
        else if(key == Characters.ESCAPE)
        {
            return true;
        }             
        return super.keyChar(key, status, time);
    }

    protected boolean navigationClick(int status, int time)
    {
        try
        {
            // use below method if want to get label value from manager.
            final int index = this.getSelectedIndex();

            if(index >= 0) {
                UiApplication.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        Dialog.alert("Selected index number : " + (index + 1));
                    }
                });
            }
        } catch (final Exception e) {
        }
        return true;   
    }

     public Object get(ListField listField, int index)
     {
         // TODO Auto-generated method stub
         return rows.elementAt(index);
     }

     public int getPreferredWidth(ListField listField)
     {
         // TODO Auto-generated method stub
         return 0;
     }

     public int indexOfList(ListField listField, String prefix, int start)
     {
         // TODO Auto-generated method stub
         return rows.indexOf(prefix, start);
     }


    /**
     *  MANAGER CLASS  
     */
    private class TableRowManager extends Manager
    {
        int _height = 0, _width = 0;
        int yPos = 0;

        public TableRowManager()
        {
            super(0);
        }

        // Causes the fields within this row manager to be layed out then
        // painted.
        public void drawRow(Graphics g, int x, int y, int width, int height)
        {
            try
            {
                _height = height;
                _width = getPreferredWidth();

                yPos = y;

                // Arrange the cell fields within this row manager.
                // set the size and position of each field.
                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(0x00CACACA);
                g.drawLine(0, 0, getPreferredWidth(), 0);

                // Restore the graphics context.
                g.popContext();
            } catch(Exception e) {
                System.out.println("Exeception : (DetailListField) 4 : " + e.toString());
            }
        }

        // Arranges this manager's controlled fields from left to right within
        // the enclosing table's columns.
        protected void sublayout(int width, int height)
        {
            try
            {

                // set the bitmap field
                Field _field0 = getField(0);
                layoutChild(_field0, (_width/3) - 30 , _height - 20);
                setPositionChild(_field0, 2, 5);

                // set the name field
                Field _field1 = getField(1);
                _field1.setFont(font);
                layoutChild(_field1, (_width/3) - 30, _field1.getPreferredHeight());
                setPositionChild(_field1, (_width/3) - 30 + 10, 5);

                Field _field2 = getField(2);
                _field2.setFont(font);              
                layoutChild(_field2, (_width/3) - 30, _field2.getPreferredHeight());
                setPositionChild(_field2, ((_width/3) - 30)*2 + 20, 5);


                setExtent(_width, _height);

            } catch(Exception e) {
                System.out.println("Exeception : (DetailListField) 5 : " + e.toString());
            }
        }
        // The preferred width of a row is defined by the list renderer.
        public int getPreferredWidth()
        {
            return (Display.getWidth());
        }
        // The preferred height of a row is the "row height" as defined in the
        // enclosing list.
        public int getPreferredHeight()
        {
            return _height;
        }       
    }
}

bt still i dont know how to get focus on single field of a single row...

秋千易 2024-10-09 06:45:49

用法:

ListCallBack _callBack = new ListCallBack();
_countries.setCallback(_callBack);

代码:

private class ListCallBack implements ListFieldCallback{

    public void drawListRow(ListField listField, Graphics graphics,
                            int index, int y, int width) {
        for(int i = 0; i <= 23; i++) {
            graphics.drawBitmap(0, y, 48, 48, (Bitmap) MyApp._flagVector.elementAt(index), 0, 0);
        }

        String text = (String)MyApp._countryVector.elementAt(index);
        graphics.drawText(text, 65, y, 0, width);
    }

    public Object get(ListField listField, int index) {
        return MyApp._countryVector.elementAt(index);
    }

    public int getPreferredWidth(ListField listField) {
        return Display.getWidth();
    }

    public int indexOfList(ListField listField, String prefix, int start) {
        return MyApp._countryVector.indexOf(prefix, start);
    }
}

usage:

ListCallBack _callBack = new ListCallBack();
_countries.setCallback(_callBack);

code:

private class ListCallBack implements ListFieldCallback{

    public void drawListRow(ListField listField, Graphics graphics,
                            int index, int y, int width) {
        for(int i = 0; i <= 23; i++) {
            graphics.drawBitmap(0, y, 48, 48, (Bitmap) MyApp._flagVector.elementAt(index), 0, 0);
        }

        String text = (String)MyApp._countryVector.elementAt(index);
        graphics.drawText(text, 65, y, 0, width);
    }

    public Object get(ListField listField, int index) {
        return MyApp._countryVector.elementAt(index);
    }

    public int getPreferredWidth(ListField listField) {
        return Display.getWidth();
    }

    public int indexOfList(ListField listField, String prefix, int start) {
        return MyApp._countryVector.indexOf(prefix, start);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文