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 7998731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:17:42+00:00 2026-06-04T15:17:42+00:00

I tried to implement the custom ListField with checkboxes in blackberry. I’m able to

  • 0

I tried to implement the custom ListField with checkboxes in blackberry. I’m able to display the list correctly. My requirement is that I need to select some multiple items using the checkbox in blackberry, but I’m not able to change the check and uncheck the checkbox. I tried in navigationClick, CheckBox.setChangeListener, HorizontalFieldManager.setChangeListener methods, but I didn’t get any solutions. Can anybody tell me what am I doing wrong?

My code is:

public class InboxWithCheckboxes extends MainScreen{
    private InboxWithCheckboxeslistfield inboxWithCheckboxeslistfield;
    public MenuItem _DeleteMessage;
    private String[]templongDBTimeStamp;
    private Database db;
    private static final int[] GRADIENT_COLORS     =
    {
        Color.PALEVIOLETRED, Color.ANTIQUEWHITE, Color.DARKTURQUOISE, Color.DEEPSKYBLUE
    };
    protected void makeMenu(Menu menu, int instance)
    {
        menu.add(_DeleteMessage);

        //Create the default menu.
        super.makeMenu(menu, instance);
    }
    public InboxWithCheckboxes(){
        inboxWithCheckboxeslistfield = new InboxWithCheckboxeslistfield();
        Background bg = BackgroundFactory.createLinearGradientBackground( 
                GRADIENT_COLORS[0], GRADIENT_COLORS[1], 
                GRADIENT_COLORS[2], GRADIENT_COLORS[3]);
        this.getMainManager().setBackground(
                bg);

        add(inboxWithCheckboxeslistfield);     
        add(new SeparatorField()); 
        db = new Database();

        _DeleteMessage = new MenuItem("DeleteMessage", 200, 10){
            public void run(){
                int index[] = inboxWithCheckboxeslistfield.getSelection();
                System.out.println("the list size is:"+inboxWithCheckboxeslistfield.getSize());
                for(int i=0;i<inboxWithCheckboxeslistfield.getSize();i++){
                int index1 = inboxWithCheckboxeslistfield.getSelectedIndex();
                System.out.println(" selected index is:"+index1);

                inboxWithCheckboxeslistfield.delete(index1);
                inboxWithCheckboxeslistfield.eraseAt(index1);

                }
                invalidate();   

            }
        };
    }
}


class InboxWithCheckboxeslistfield extends ListField implements ListFieldCallback  {
    public Vector rows;
    private TableRowManager row ;
    public TableRowManager rowManager;
    private LabelField UserName,Message,Timestamp;
    private HorizontalFieldManager hfmcheck;

    private CheckboxField checkbox;

    private Database db;
    private Vector inboxdatavector;
    private String[] msg,key,userinfo,timearray;
    private long[] timeStamp;
    /* Border For EditFields */
    Border bdr = BorderFactory.createRoundedBorder(new XYEdges(4, 4, 4, 4),
            Border.STYLE_SOLID);


    /**
     * Creates a new MyScreen object
     */
    public InboxWithCheckboxeslistfield() {
        // TODO Auto-generated constructor stub

        super(0, ListField.MULTI_SELECT);
        setRowHeight(120);
        setCallback(this);
        rows = new Vector();
        db = new Database();
        inboxdatavector = db.fetchDataInbox();
        int count = db.getcountInbox();
        msg = new String[count];
        key =  new String[count];
        userinfo =  new String[count];
        timearray = new String[count];
        timeStamp = new long[count];
        for (int i = 0; i < count; i++) {

            row = new TableRowManager() { 
                public void paint(Graphics g) { 
                    g.setBackgroundColor(Color.BLACK); 
                    g.fillRect(0, 0, getWidth(), getHeight()); 
                    g.setColor(Color.BLACK); 
                    g.clear(); 
                    super.paint(g); 
                } 
            }; 
            try{
                byte[] a = (byte[]) inboxdatavector.elementAt(i);
                ByteArrayInputStream bais = new ByteArrayInputStream(a);
                DataInputStream dis = new DataInputStream(bais);
                msg[i]= dis.readUTF();
                key[i] = dis.readUTF();
                userinfo[i] = dis.readUTF();
                timeStamp[i] = dis.readLong();
                timearray[i] = convertMillisecondsToDate(timeStamp[i]);
                System.out.println("msg is "+msg[i]);
                System.out.println("key is "+key[i]);
                System.out.println("userinfo is "+userinfo[i]);
                System.out.println("timeStamp is "+timeStamp[i]);

                bais.close();
                dis.close();
            } catch (Exception e) {
                e.printStackTrace();
            }



            UserName = new LabelField("" + String.valueOf(i),
                    DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
                    | DrawStyle.LEFT);
            UserName.setText(userinfo[i]);
            row.add(UserName);
            hfmcheck = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
            row.add(hfmcheck);
            checkbox = new CheckboxField("",false,Field.USE_ALL_WIDTH){
                public void paint(Graphics graphics) {
                    graphics.setColor(Color.WHITE);
                    super.paint(graphics);
                }
            };
            hfmcheck.add(checkbox);
            hfmcheck.setChangeListener(new FieldChangeListener() {

                public void fieldChanged(Field field, int context) {
                    // TODO Auto-generated method stub
                    System.out.println("entered into hfmfield");
                    checkbox.setChecked(true);
                }
            });
            Message = new LabelField("" + String.valueOf(i),
                    DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
                    | DrawStyle.RIGHT);
            Message.setText(msg[i]);
            row.add(Message);


            Timestamp = new LabelField("" + String.valueOf(i),
                    DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
                    | DrawStyle.RIGHT);
            Timestamp.setText(timearray[i]);
            row.add(Timestamp);

            rows.addElement(row);

        }
        for (int i = 0; i < userinfo.length; i++) {
            timearray[i] = convertMillisecondsToDate(timeStamp[i]);
            System.out.println("the time is:"+timearray[i]);

        }
        /*checkbox.setChangeListener(new FieldChangeListener() {

            public void fieldChanged(Field field, int context) {
                // TODO Auto-generated method stub
                System.out.println("enter into checked changed.");
                checkbox.setChecked(true);

            }
        });*/
        setSize(rows.size());


    }

    public void drawListRow(ListField listField, Graphics graphics, int index,
            int y, int width) {
        // TODO Auto-generated method stub

        InboxWithCheckboxeslistfield list = (InboxWithCheckboxeslistfield) listField;
        rowManager = (TableRowManager) list.rows.elementAt(index);
        ((TableRowManager) rowManager).drawRow(graphics, 0, y, width, list.getRowHeight());



    }
    public void erase() {  
        rows.removeAllElements();  
    }

    public void eraseAt(int index) {  
        rows.removeElementAt(index);

    }
    private class TableRowManager extends Manager {

        protected TableRowManager(){
            super(0);
        }

        public void drawRow(Graphics graphics, int i, int y, int width,
                int rowHeight) {
            // TODO Auto-generated method stub
            // Arrange the cell fields within this row manager.
            layout(width, rowHeight);

            // Place this row manager within its enclosing list.
            setPosition(i, y);

            // Apply a translating/clipping transformation to the graphics
            // context so that this row paints in the right area.
            graphics.pushRegion(getExtent());

            // Paint this manager's controlled fields.
            subpaint(graphics);
            graphics.setColor(0x00CACACA);
            graphics.drawLine(0, 0, getPreferredWidth(), 0);

            // Restore the graphics context.
            graphics.popContext();

        }


        protected void sublayout(int width, int height) {
            // TODO Auto-generated method stub
            // set the size and position of each field.
            int fontHeight = Font.getDefault().getHeight();
            int preferredWidth = getPreferredWidth();

            Field field = getField(0);

            layoutChild(field, preferredWidth, 50); 
            setPositionChild(field, 10, 5);

            field = getField(1);
            layoutChild(field, preferredWidth, 150); 
            setPositionChild(field, 10,40);


            // set the list name label field
            field = getField(2);
            layoutChild(field, 300, fontHeight + 1); 
            //setPositionChild(field, 1, 2); 
            setPositionChild(field, 80, fontHeight );

            // set the due time name label field
            field = getField(3);
            layoutChild(field, 150, fontHeight + 1);
            setPositionChild(field, 500, fontHeight );



            setExtent(getPreferredWidth(), getPreferredHeight());

        }
        // 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 getRowHeight();       
        } 


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

    public int getPreferredWidth(ListField listField) { 
        return 0; 
    } 

    public int indexOfList(ListField listField, String prefix, int start) { 
        return 0; 
    } 


    public String convertMillisecondsToDate(long timeStamp) {

        // Create a DateFormatter object for displaying date information.

        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");

        java.util.Date date = new java.util.Date(timeStamp);
        System.out.println("the date is:"+formatter.formatLocal(date.getTime()));
        return formatter.formatLocal(date.getTime());
    }
    protected boolean navigationClick(int status, int time) {
        /*_DeleteMessage = new MenuItem("DeleteMessage", 200, 10){
            public void run(){
                System.out.println("entered into delete item");
                int index = getSelectedIndex();
                System.out.println(" selected index is:"+index);
                for(int i=0;i<rows.size();i++){
                    rows.removeElementAt(index);
                    invalidate();
                }
            }

        };*/
        return true;

    }


}
  • 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-06-04T15:17:44+00:00Added an answer on June 4, 2026 at 3:17 pm

    try this –

    CheckboxField box;
    Vector box1 = new Vector();
    boolean checked = false;
    
    for(int i=0;i<fbFrndsVector.size();i++){
        //your object class and vector.     
        FriendsRequestObject co_vec = (FriendsRequestObject)fbFrndsVector.elementAt(i);
    
        String name=co_vec.getSender_name();
        String id=co_vec.getSender_id();
    
        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);
             vfm.add(box);
    
    
    }
    
    add(vfm);
    

    //on your button click, write the below code-

        Vector selected_frnd=new Vector();
        private Vector _selected_frnds;
    
    
            for(int d=0; d<box1.size(); d++){
                    CheckboxField box=(CheckboxField)box1.elementAt(d);
                      if(box.getChecked()==true){
                        FriendsRequestObject co_vec = (FriendsRequestObject)fbFrndsVector.elementAt(d);
    
                        String name_ = co_vec.getSender_name();
                        String id_ = co_vec.getSender_id();
                        FriendsRequestObject sfrnds = new FriendsRequestObject(id_, name_);
                        selected_frnd.addElement(sfrnds);
    
    
                      }
                    }
    

    the vector selected_frnd will contains all the selected items.

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

Sidebar

Related Questions

I once tried to implement Comet in PHP. Soon, I found that PHP is
I want to implement Custom Dialog in Android. However , when I tried it
I got an app, where i tried to implement custom camera. This is source
As The Title said, I tried to implement a custom taxonomy in wordpress, i
I am creating a custom photography CMS system and need to implement a user
I tried to implement __concat__ , but it didn't work >>> class lHolder(): ...
I tried to implement XOR swap in python. x,y= 10,20 x,y,x = x^y,x^y,x^y print('%s
I tried to implement the following in less: nav > ul > li:first-child using:
I tried to implement FizzBuzz in DCPU-16. I use this web emulator: http://mappum.github.com/DCPU-16/ (repository:
I have tried to implement css sticky footer on my page but it doesn't

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.