黑莓中 CustomListField 中的复选框

发布于 2024-12-28 11:19:31 字数 2884 浏览 0 评论 0原文

我正在创建一个自定义列表。在每一行中,我都有一个图像、一些文本字段和一个复选框。但我无法选中和取消选中该复选框。 我已浏览此链接但无法解决我的问题。

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/How_To__-_Create_a_ListField_with_check_boxes.html?nodeid=1165752&vernum=0

这将在菜单中添加一个菜单项来更改复选框 地位。 我想要正常的复选框行为。 请帮助

这是我的代码,

class CustomList extends ListField implements ListFieldCallback
{

public Vector rows;
private Bitmap p1;
int z = this.getRowHeight();    
LabelField task,task2,task3;
CheckboxField checkbox[]= new CheckboxField[40];
int rowcount;
public CustomList(int rowcount,String text1,double text2,String type,Bitmap p)
{
    super(0, ListField.MULTI_SELECT);
    this.rowcount= rowcount;
    setRowHeight(z*3);
    setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);
    setCallback(this);        
    p1 = p;     
    rows = new Vector();

    for (int x = 0; x < rowcount; x++) 
    {
        checkbox[x]=new CheckboxField("",false,Field.USE_ALL_HEIGHT|Field.EDITABLE|Field.FIELD_VCENTER|Field.FOCUSABLE);
    }
    for (int x = 0; x < rowcount; x++) 
    {
        TableRowManager row = new TableRowManager();            
        row.add(checkbox[x]);
        row.add(new BitmapField(p1));
        task= new LabelField("abc");
        row.add(task);
        task2=new LabelField("abc2");
        row.add(task2);
        task3= new LabelField("abc3");
        row.add(task3);
        rows.addElement(row);
    }
    setSize(rows.size());
}
public void drawListRow(ListField listField, Graphics g, int index, int y,int width) 
{
    CustomList list = (CustomList) listField;
    TableRowManager rowManager = (TableRowManager) list.rows.elementAt(index);
    rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}

private class TableRowManager extends Manager 
{
    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) 
    {
        layout(width, height);
        setPosition(x, y);
        g.pushRegion(getExtent());
        subpaint(g);
        g.setColor(0x00CACACA);
        g.popContext();
    }
    protected void sublayout(int width, int height) 
    {
        // set the size and position of each field.
    }
    public int getPreferredWidth() 
    {
        return UIConstants.SCREEN_WIDTH;
    }
    public int getPreferredHeight() 
    {
        return getRowHeight();
    }
}
}

我正在尝试使用复选框实现列表字段,并且我在知识库中看到了它的代码。

但我希望当我单击复选框时,它应该仅被选中或取消选中,当我单击该行的其余部分(即除复选框之外的任何地方)时,如果不选中复选框,则不会发生任何事情

我该怎么做?或者我应该做点别的事情来做到这一点..请建议..

I am creating a CustomList. In each row I am having a image, some text fields and a checkbox. But i am not able to check and uncheck the checkbox.
I have gone through this link but cant solve my problem.

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/How_To_-_Create_a_ListField_with_check_boxes.html?nodeid=1165752&vernum=0

this will add a menu item in the menu to change the checkbox status.
I want the normal checkbox behaviour.
Please help

this is my code

class CustomList extends ListField implements ListFieldCallback
{

public Vector rows;
private Bitmap p1;
int z = this.getRowHeight();    
LabelField task,task2,task3;
CheckboxField checkbox[]= new CheckboxField[40];
int rowcount;
public CustomList(int rowcount,String text1,double text2,String type,Bitmap p)
{
    super(0, ListField.MULTI_SELECT);
    this.rowcount= rowcount;
    setRowHeight(z*3);
    setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);
    setCallback(this);        
    p1 = p;     
    rows = new Vector();

    for (int x = 0; x < rowcount; x++) 
    {
        checkbox[x]=new CheckboxField("",false,Field.USE_ALL_HEIGHT|Field.EDITABLE|Field.FIELD_VCENTER|Field.FOCUSABLE);
    }
    for (int x = 0; x < rowcount; x++) 
    {
        TableRowManager row = new TableRowManager();            
        row.add(checkbox[x]);
        row.add(new BitmapField(p1));
        task= new LabelField("abc");
        row.add(task);
        task2=new LabelField("abc2");
        row.add(task2);
        task3= new LabelField("abc3");
        row.add(task3);
        rows.addElement(row);
    }
    setSize(rows.size());
}
public void drawListRow(ListField listField, Graphics g, int index, int y,int width) 
{
    CustomList list = (CustomList) listField;
    TableRowManager rowManager = (TableRowManager) list.rows.elementAt(index);
    rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}

private class TableRowManager extends Manager 
{
    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) 
    {
        layout(width, height);
        setPosition(x, y);
        g.pushRegion(getExtent());
        subpaint(g);
        g.setColor(0x00CACACA);
        g.popContext();
    }
    protected void sublayout(int width, int height) 
    {
        // set the size and position of each field.
    }
    public int getPreferredWidth() 
    {
        return UIConstants.SCREEN_WIDTH;
    }
    public int getPreferredHeight() 
    {
        return getRowHeight();
    }
}
}

I am trying to implement listfield with checkboxes and i have seen its code in the knowledge base.

But i want that when i click on the checkbox it should be checked or unchecked onlyand when i click on the rest part of the row, i.e. anywhere except the checkbox then nothing should occur without checking the checkbox

How can i do that ?? Or i should do something else to do it.. Please suggest..

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

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

发布评论

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

评论(2

瀞厅☆埖开 2025-01-04 11:19:31

做一些类似这样的事情,您要重写表行管理器类中的 sublayOut method() ,

protected void sublayout(int width, int height) 
{
    Field field = getField(0);            
                layoutChild(field, Display.getWidth(),   Display.getHeight());             
                setPositionChild(field, 10, 20);

Field field = getField(0);            
                layoutChild(field, Display.getWidth(),    Display.getHeight());            
                setPositionChild(field, 10, 20);

                //Set field           
                field = getField(1);
                layoutChild(field, 120, fontHeight - 1 );             
                setPositionChild(field, 70, 05);

                // set the list field             
                field = getField(2);              
                layoutChild(field, 150, fontHeight +10);              
                setPositionChild(field, 70, 25);

                // set the field               
                field = getField(3);              
                layoutChild(field, (Display.getWidth()/6)-12, fontHeight + 10);       
                setPositionChild(field, 70, 45);    
                setExtent(preferredWidth, getPreferredHeight());
}

根据您的要求更改填充。

您还可以检查此链接 创建一个带有复选框的列表字段。谢谢

Do some thing like this where you are overriding your sublayOut method() in table row manager class

protected void sublayout(int width, int height) 
{
    Field field = getField(0);            
                layoutChild(field, Display.getWidth(),   Display.getHeight());             
                setPositionChild(field, 10, 20);

Field field = getField(0);            
                layoutChild(field, Display.getWidth(),    Display.getHeight());            
                setPositionChild(field, 10, 20);

                //Set field           
                field = getField(1);
                layoutChild(field, 120, fontHeight - 1 );             
                setPositionChild(field, 70, 05);

                // set the list field             
                field = getField(2);              
                layoutChild(field, 150, fontHeight +10);              
                setPositionChild(field, 70, 25);

                // set the field               
                field = getField(3);              
                layoutChild(field, (Display.getWidth()/6)-12, fontHeight + 10);       
                setPositionChild(field, 70, 45);    
                setExtent(preferredWidth, getPreferredHeight());
}

change the padding as your require ments.

And you can also check this link create a listField with check box. Thanks

寂寞花火° 2025-01-04 11:19:31
  boolean checked = false;
  Vector box1 = new Vector();  
  for(int i=0;i<vector.size();i++){
    FriendsRequestObject co_vec = (FriendsRequestObject)vector.elementAt(i);
    String name=co_vec.getSender_name();
    CheckboxField box = new CheckboxField(" "+name , checked, Field.USE_ALL_WIDTH){
        public void paint(Graphics graphics) {
               graphics.setColor(Color.WHITE);
              super.paint(graphics);
            }
         };
         box1.addElement(box);
         box.setMargin(8, 0, 0, 5);
         add(box);

      }

然后添加一个按钮。在按钮的点击监听器上,

         for(int d=0; d<box1.size(); d++){
            CheckboxField box=(CheckboxField)box1.elementAt(d);
                  if(box.getChecked()==true){
                    FriendsRequestObject co_vec = (FriendsRequestObject)vector.elementAt(d);
                    String name_ = co_vec.getSender_name();
                    Dialog.alert(name_);// here you can implement your code
                  }
                }
  boolean checked = false;
  Vector box1 = new Vector();  
  for(int i=0;i<vector.size();i++){
    FriendsRequestObject co_vec = (FriendsRequestObject)vector.elementAt(i);
    String name=co_vec.getSender_name();
    CheckboxField box = new CheckboxField(" "+name , checked, Field.USE_ALL_WIDTH){
        public void paint(Graphics graphics) {
               graphics.setColor(Color.WHITE);
              super.paint(graphics);
            }
         };
         box1.addElement(box);
         box.setMargin(8, 0, 0, 5);
         add(box);

      }

then add a button. On the click listener of the button,

         for(int d=0; d<box1.size(); d++){
            CheckboxField box=(CheckboxField)box1.elementAt(d);
                  if(box.getChecked()==true){
                    FriendsRequestObject co_vec = (FriendsRequestObject)vector.elementAt(d);
                    String name_ = co_vec.getSender_name();
                    Dialog.alert(name_);// here you can implement your code
                  }
                }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文