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

  • Home
  • SEARCH
  • 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 8981383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:19:20+00:00 2026-06-15T20:19:20+00:00

I am implementing a simple app, where in the registration page user can select

  • 0

I am implementing a simple app, where in the registration page user can select news categories. Requirements are below

  1. All the categories are the CheckBoxField’s. User have to select at least one category.
  2. Select all CheckBox will allow to select all/deselect all categories CheckBox.
  3. If user manually selects all checkbox fields then “Select All” checkbox must be selected.

Approaches: I have created the categories checkbox in a loop.

for(int i=0;i<interests.length;i++){
    allFields[i] = new ColorCheckBoxField(interests[i], false, checkBoxStyle | USE_ALL_WIDTH);
    allFields[i].setCookie(i+"");
    allFields[i].setFont(bodyFont);
    allFields[i].setChangeListener(new FieldChangeListener() {
         public void fieldChanged(Field field, int context) {
            ColorCheckBoxField tempChoice = (ColorCheckBoxField)field;
            int index =Integer.parseInt(tempChoice.getCookie().toString().trim());
            //set the selection
            if(tempChoice.getChecked()){
                parent.selectInterest(index);
            }

            boolean flag = true;
            int[] intrests = parent.getSelectedInterest();
            for (int i = 0; i < intrests.length; i++) {                     
                if(intrests[i]==0){
                    flag = false;
                }
            }

            if(flag==true){
                selectAll.setChecked(flag); // select all is Checkbox object
            }else{
                selectAll.setChecked(false);
            }
        }
    });
    vfm.add(allFields[i]);
} 

My selectAll checkbox logic is

        selectAll = new ColorCheckBoxField("Select All", false, checkBoxStyle | USE_ALL_WIDTH);
        selectAll.setChangeListener(new FieldChangeListener() {         
            public void fieldChanged(Field field, int context) {
                ColorCheckBoxField temp = (ColorCheckBoxField) field;
                //if (context == FieldChangeListener.PROGRAMMATIC ) {
                    checkAll(temp.getChecked()); // it loops through all checkbox and set them checked
                //}
            }
        }); 

        innerHfm.add(selectAll);

I understand the problem, its due to infinite loop. I have used “FieldChangeListener.PROGRAMMATIC” but that wont help because i want the field listener to work for both pragmatically and manually. I don’t have any option left to fix. Any hack will help me?

  • 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-15T20:19:22+00:00Added an answer on June 15, 2026 at 8:19 pm

    That’s correct that you have to use FieldChangeListener.PROGRAMMATIC. But you have to use it with interest checkboxes instead of using it for selectAll checkbox.

    Please add one defensive check to FieldChangeListener for interest checkboxes:

    if ( nonProgrammaticChange(context) ) {
       ColorCheckBoxField tempChoice = (ColorCheckBoxField)field;
       int index = Integer.parseInt(tempChoice.getCookie().toString().trim());
       ...
    }
    

    Where nonProgrammaticChange is:

    private boolean nonProgrammaticChange (int context) {
        return (context & FieldChangeListener.PROGRAMMATIC) != FieldChangeListener.PROGRAMMATIC;
    }
    

    I see bug in your code – you don’t clear interest in parent if checkbox is unchecked.

    Minor improvements as for me – use Vector where you’ll store indexes of selected checkboxes. This will allow to replace this code:

    boolean flag = true;
    int[] intrests = parent.getSelectedInterest();
    for ( int i = 0; i < intrests.length; i++ ) {                     
         if( intrests[i] == 0 ) {
              flag = false;
         }
    }
    

    To this code:

    selectedInterestIndexes.size() == interests.length
    

    And probably this will give you less iteration in other places.

    As well I would work more on removal of duplicates and code readability.

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

Sidebar

Related Questions

I'm developing my first iPhone app, and while implementing user preferences, I have a
I'm Implementing a simple web app using Django, I want to get user's location
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
I am implementing a simple version of a linux shell in c. I have
I am implementing a simple iOS solitaire game that allows the user to drag
I am implementing a simple in-app browser. In my home view ( UITableViewController ),
I have a very simple TableViewController. I'm only implementing the data source methods and
I'm using node, express and connect for a simple app and have basic HTTP
very new to signalR, and have rolled up a very simple app that will
I have a simple webapp in Django for an iPhone app. I want to

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.