Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7577345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:09:41+00:00 2026-05-30T17:09:41+00:00

I have made list view with checkboxes. I have read similar articles n many

  • 0

I have made list view with checkboxes. I have read similar articles n many people have suggested to do changes in drawlistRow but it is not happening. Can u suggest me where should i change to make it a multi line list.The code snippet is :
Updated: I updated my code and it is still not working

 public class CheckboxListField extends MainScreen implements ListFieldCallback, FieldChangeListener {
    int mCheckBoxesCount = 5;
    private Vector _listData = new Vector();
    private ListField listField;
    private ContactList blackBerryContactList;
    private BlackBerryContact blackBerryContact;
    private Vector blackBerryContacts;
    private MenuItem _toggleItem;
    ButtonField button;
    BasicEditField mEdit;
    CheckboxField cb;
    CheckboxField[] chk_service;
    HorizontalFieldManager hm4;
    CheckboxField[] m_arrFields;
     boolean mProgrammatic = false;
     public static StringBuffer sbi = new StringBuffer();
     VerticalFieldManager checkBoxGroup = new VerticalFieldManager();
     LabelField task;

    //A class to hold the Strings in the CheckBox and it's checkbox state (checked or unchecked).
    private class ChecklistData
    {
        private String _stringVal;
        private boolean _checked;

       ChecklistData()
        {
            _stringVal = "";
            _checked = false;
        }

        ChecklistData(String stringVal, boolean checked)
        {
            _stringVal = stringVal;
            _checked = checked;
        }

        //Get/set methods.
        private String getStringVal()
        {
            return _stringVal;
        }

        private boolean isChecked()
        {
            return _checked;
        }

        private void setStringVal(String stringVal)
        {
            _stringVal = stringVal;
        }

        private void setChecked(boolean checked)
        {
            _checked = checked;
        }

        //Toggle the checked status.
        private void toggleChecked()
        {
            _checked = !_checked;
        }
    }

    CheckboxListField()
    {   
        _toggleItem = new MenuItem("Change Option", 200, 10) 
        {
            public void run()
            {
                //Get the index of the selected row.
                int index = listField.getSelectedIndex();

                //Get the ChecklistData for this row.
                ChecklistData data = (ChecklistData)_listData.elementAt(index);

                //Toggle its status.
                data.toggleChecked();

                //Update the Vector with the new ChecklistData.
                _listData.setElementAt(data, index);

                //Invalidate the modified row of the ListField.
                listField.invalidate(index);

               if (index != -1 && !blackBerryContacts.isEmpty())
               {
                   blackBerryContact =
                       (BlackBerryContact)blackBerryContacts.
                       elementAt(listField.getSelectedIndex());
                   ContactDetailsScreen contactDetailsScreen =
                       new ContactDetailsScreen(blackBerryContact);
                   UiApplication.getUiApplication().pushScreen(contactDetailsScreen);
               }
            }
        };   
        listField = new ListField();
        listField.setRowHeight(getFont().getHeight() * 2);
        listField.setCallback(this);
        reloadContactList();

        //CheckboxField[] cb = new CheckboxField[blackBerryContacts.size()];
        for(int count = 0; count < blackBerryContacts.size(); ++count)
        {
            BlackBerryContact item =
                (BlackBerryContact)blackBerryContacts.elementAt(count);
            String displayName = getDisplayName(item);
            CheckboxField cb = new CheckboxField(displayName, false);
            cb.setChangeListener(this);
            add(cb);
            listField.insert(count);
        }
        blackBerryContacts.addElement(cb);
        add(checkBoxGroup);
    }

    protected void makeMenu(Menu menu, int instance)
    {
        menu.add(new MenuItem("Get", 2, 2) {
            public void run() {
                for (int i = 0; i < checkBoxGroup.getFieldCount(); i++) {
                //for(int i=0; i<blackBerryContacts.size(); i++) {
                    CheckboxField checkboxField = (CheckboxField)checkBoxGroup
                        .getField(i);           
                    if (checkboxField.getChecked()) {
                        sbi.append(checkboxField.getLabel()).append("\n");
                    }
                }
                Dialog.inform("Selected checkbox text::" + sbi);
            }
        });
        super.makeMenu(menu, instance);
    }      

    private boolean reloadContactList()
    {
        try {
            blackBerryContactList =
                (ContactList)PIM.getInstance().openPIMList
                (PIM.CONTACT_LIST, PIM.READ_ONLY);

            Enumeration allContacts = blackBerryContactList.items();
            blackBerryContacts = enumToVector(allContacts);
            listField.setSize(blackBerryContacts.size());
            return true;
        }   catch (PIMException e)
        {
          return false;
        }
    } 

    //Convert the list of contacts from an Enumeration to a Vector
    private Vector enumToVector(Enumeration contactEnum) {
        Vector v = new Vector();

        if (contactEnum == null)
          return v;

        while (contactEnum.hasMoreElements()) {
          v.addElement(contactEnum.nextElement());
        }

        return v;
      }

    public void drawListRow(ListField list, Graphics graphics, int index, int y, int w) 
    {
        ChecklistData currentRow = (ChecklistData)this.get(list, index); 
        StringBuffer rowString = new StringBuffer();

        if (currentRow.isChecked())
        {
            rowString.append(Characters.BALLOT_BOX_WITH_CHECK);
        }
        else
        {
            rowString.append(Characters.BALLOT_BOX);
        }

        //Append a couple spaces and the row's text.
        rowString.append(Characters.SPACE);
        rowString.append(Characters.SPACE);
        rowString.append(currentRow.getStringVal());

        //graphics.drawText("ROW", 0, y, 0, w);
        //String rowNumber = "one";
        //Draw the text.
        graphics.drawText(rowString.toString(), 0, y, 0, w);
        /*graphics.drawText("ROW " + rowNumber, y, 0, w);
        graphics.drawText("ROW NAME", y, 20, w);
        graphics.drawText("row details", y + getFont().getHeight(), 20, w); */
    }

    public void drawRow(Graphics g, int x, int y, int width, int height) {
        // Arrange the cell fields within this row manager.
        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();
    }
    public static String getDisplayName(Contact contact) 
      {
          if (contact == null)
          {
              return null;    
          }

          String displayName = null;

          // First, see if there is a meaningful name set for the contact.
          if (contact.countValues(Contact.NAME) > 0) {
              final String[] name = contact.getStringArray(Contact.NAME, 0);
              final String firstName = name[Contact.NAME_GIVEN];
              final String lastName = name[Contact.NAME_FAMILY];
              if (firstName != null && lastName != null) {
                  displayName = firstName + " " + lastName;
              } else if (firstName != null) {
                  displayName = firstName;
              } else if (lastName != null) {
                  displayName = lastName;
              }

              if (displayName != null) {
                  final String namePrefix = name[Contact.NAME_PREFIX];
                  if (namePrefix != null) {
                      displayName = namePrefix + " " + displayName;
                  }
                  return displayName;
              }
          }
          return displayName;
      }

    //Returns the object at the specified index.
    public Object get(ListField list, int index) 
    { 
        return _listData.elementAt(index);
        /*if (listField == list)
        {
            //If index is out of bounds an exception will be thrown,
            //but that's the behaviour we want in that case.
            //return blackBerryContacts.elementAt(index);
            _listData = (Vector) blackBerryContacts.elementAt(index);
            return _listData.elementAt(index);
        }
        return null;*/
    }

    //Returns the first occurence of the given String, bbeginning the search at index, 
    //and testing for equality using the equals method.
    public int indexOfList(ListField list, String p, int s) 
    {
        //return listElements.getSelectedIndex();
        //return _listData.indexOf(p, s);
        return -1;
    }

    //Returns the screen width so the list uses the entire screen width.
    public int getPreferredWidth(ListField list) 
    {
        return Graphics.getScreenWidth();
        //return Display.getWidth();
    }

    public void fieldChanged(Field field, int context) {
      boolean mProgrammatic = false;

        if (!mProgrammatic) {
        mProgrammatic = true;
        CheckboxField cbField = (CheckboxField) field;
        int index = blackBerryContacts.indexOf(cbField);

        if (cbField.getChecked())
        {
           for(int i=0;i<blackBerryContacts.size();i++)
           {
           Dialog.inform("Selected::" + cbField.getLabel());
           sbi=new StringBuffer();
           sbi.append(cbField.getLabel());

           }                 
        }

        mProgrammatic = false;
    }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:09:43+00:00Added an answer on May 30, 2026 at 5:09 pm

    This code may be improved with:

    1. Using ListField instead of VerticalFieldManager + CheckboxField array (ListField is much more faster, 100+ controls may slow down UI)
    2. Using simple array instead of vector in list data (it’s faster)
    3. Moving contacts load from UI thread (we should aware of blocking UI thread with heavy procedures like IO, networking or work with contact list)

    Actually using ListField with two line rows has one issue: we have to set the same height for all rows in ListField. So there always will be two lines per row, no matter if we will use second line or not. But it’s really better than UI performance issues.

    See code:

    public class CheckboxListField extends MainScreen implements
            ListFieldCallback {
        private ChecklistData[] mListData = new ChecklistData[] {};
        private ListField mListField;
        private Vector mContacts;
        private MenuItem mMenuItemToggle = new MenuItem(
                "Change Option", 0, 0) {
            public void run() {
                toggleItem();
            };
        };
    
        private MenuItem mMenuItemGet = new MenuItem("Get", 0,
                0) {
            public void run() {
                StringBuffer sbi = new StringBuffer();
                for (int i = 0; i < mListData.length; i++) {
                    ChecklistData checkboxField = mListData[i];
                    if (checkboxField.isChecked()) {
                        sbi.append(checkboxField.getStringVal())
                                .append("\n");
                    }
                }
                Dialog.inform("Selected checkbox text::\n"
                        + sbi);
            }
        };
    
        // A class to hold the Strings in the CheckBox and it's checkbox state
        // (checked or unchecked).
        private class ChecklistData {
            private String _stringVal;
            private boolean _checked;
    
            ChecklistData(String stringVal, boolean checked) {
                _stringVal = stringVal;
                _checked = checked;
            }
    
            // Get/set methods.
            private String getStringVal() {
                return _stringVal;
            }
    
            private boolean isChecked() {
                return _checked;
            }
    
            // Toggle the checked status.
            private void toggleChecked() {
                _checked = !_checked;
            }
        }
    
        CheckboxListField() {
            // toggle list field item on navigation click
            mListField = new ListField() {
                protected boolean navigationClick(int status,
                        int time) {
                    toggleItem();
                    return true;
                };
            };
            // set two line row height
            mListField.setRowHeight(getFont().getHeight() * 2);
            mListField.setCallback(this);
            add(mListField);
    
            // load contacts in separate thread
            loadContacts.run();
        }
    
        protected Runnable loadContacts = new Runnable() {
            public void run() {
                reloadContactList();
                // fill list field control in UI event thread
                UiApplication.getUiApplication().invokeLater(
                        fillList);
            }
        };
    
        protected Runnable fillList = new Runnable() {
            public void run() {
                int size = mContacts.size();
                mListData = new ChecklistData[size];
                for (int i = 0; i < mContacts.size(); i++) {
                    BlackBerryContact item = (BlackBerryContact) mContacts
                            .elementAt(i);
                    String displayName = getDisplayName(item);
                    mListData[i] = new ChecklistData(
                            displayName, false);
                }
                mListField.setSize(size);
            }
        };
    
        protected void toggleItem() {
            // Get the index of the selected row.
            int index = mListField.getSelectedIndex();
            if (index != -1) {
                // Get the ChecklistData for this row.
                ChecklistData data = mListData[index];
    
                // Toggle its status.
                data.toggleChecked();
    
                // Invalidate the modified row of the ListField.
                mListField.invalidate(index);
    
                BlackBerryContact contact = (BlackBerryContact) mContacts
                        .elementAt(mListField
                                .getSelectedIndex());
    
                // process selected contact here
    
            }
        }
    
        protected void makeMenu(Menu menu, int instance) {
            menu.add(mMenuItemToggle);
            menu.add(mMenuItemGet);
            super.makeMenu(menu, instance);
        }
    
        private boolean reloadContactList() {
            try {
                ContactList contactList = (ContactList) PIM
                        .getInstance()
                        .openPIMList(PIM.CONTACT_LIST,
                                PIM.READ_ONLY);
    
                Enumeration allContacts = contactList.items();
                mContacts = enumToVector(allContacts);
                mListField.setSize(mContacts.size());
                return true;
            } catch (PIMException e) {
                return false;
            }
        }
    
        // Convert the list of contacts from an Enumeration to a Vector
        private Vector enumToVector(Enumeration contactEnum) {
            Vector v = new Vector();
    
            if (contactEnum == null)
                return v;
    
            while (contactEnum.hasMoreElements()) {
                v.addElement(contactEnum.nextElement());
            }
    
            return v;
        }
    
        public void drawListRow(ListField list,
                Graphics graphics, int index, int y, int w) {
            Object obj = this.get(list, index);
            if (obj != null) {
                ChecklistData currentRow = (ChecklistData) obj;
                StringBuffer rowString = new StringBuffer();
    
                if (currentRow.isChecked()) {
                    rowString
                            .append(Characters.BALLOT_BOX_WITH_CHECK);
                } else {
                    rowString.append(Characters.BALLOT_BOX);
                }
                // Append a couple spaces and the row's text.
                rowString.append(Characters.SPACE);
                rowString.append(Characters.SPACE);
                rowString.append(currentRow.getStringVal());
                // Draw the text.
                graphics.drawText(rowString.toString(), 0, y,
                        0, w);
                String secondLine = "Lorem ipsum dolor sit amet, "
                        + "consectetur adipiscing elit.";
                graphics.drawText(secondLine, 0, y
                        + getFont().getHeight(),
                        DrawStyle.ELLIPSIS, w);
            } else {
                graphics.drawText("No rows available.", 0, y,
                        0, w);
            }
        }
    
        public static String getDisplayName(Contact contact) {
            if (contact == null) {
                return null;
            }
            String displayName = null;
            // First, see if there is a meaningful name set for the contact.
            if (contact.countValues(Contact.NAME) > 0) {
                final String[] name = contact.getStringArray(
                        Contact.NAME, 0);
                final String firstName = name[Contact.NAME_GIVEN];
                final String lastName = name[Contact.NAME_FAMILY];
                if (firstName != null && lastName != null) {
                    displayName = firstName + " " + lastName;
                } else if (firstName != null) {
                    displayName = firstName;
                } else if (lastName != null) {
                    displayName = lastName;
                }
                if (displayName != null) {
                    final String namePrefix = name[Contact.NAME_PREFIX];
                    if (namePrefix != null) {
                        displayName = namePrefix + " "
                                + displayName;
                    }
                    return displayName;
                }
            }
            return displayName;
        }
    
        // Returns the object at the specified index.
        public Object get(ListField list, int index) {
            Object result = null;
            if (mListData.length > index) {
                result = mListData[index];
            }
            return result;
        }
    
        // Returns the first occurrence of the given String,
        // beginning the search at index, and testing for
        // equality using the equals method.
        public int indexOfList(ListField list, String p, int s) {
            return -1;
        }
    
        // Returns the screen width so the list uses the entire screen width.
        public int getPreferredWidth(ListField list) {
            return Graphics.getScreenWidth();
            // return Display.getWidth();
        }
    }
    

    blackberry chackbox two lines per row list field

    Have a nice coding!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a list view containing two childs. Now i am trying to
I have made an application which calls the phone's contact list but i want
I m working on android. i have made expandable list view and its working
I'm working on application where I have a custom made List View, with image
i have made menu list containing play, settings, exit. but clicking the button doesn
i'm building small sms-like application. I made conversation list view, but there is a
I have made a list with few elements in it. Now everything looks right,
I have made a basic unordered list. <ul> <li><a>abc</a></li> <li><a>def</a></li> <li><a>ghi</a></li> <li><a>jkl</a></li> </ul> I
I have made a XML parser that list correctly in the UITableViewController. It passes
I have made a page in which i m using a list to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.