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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:24:39+00:00 2026-06-11T18:24:39+00:00

i have created check boxes using loop and i want to validate it. Like

  • 0

i have created check boxes using loop and i want to validate it. Like i just want to check only 3 from the check boxes , when i press on the 4th one it should show an alert and uncheck it.

enter image description here

And i am able to get the alert when i press the 4the one but it is not unchecking.

anybody faced such issue and how did you solve it ?

  • 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-11T18:24:41+00:00Added an answer on June 11, 2026 at 6:24 pm
    int i;
    for (i = 0; i < 20; i++) {
        CheckBox ch = new CheckBox(this);
        ch.setTag(Integer.valueOf(i));
        ch.setText("CheckBox " + i);
        ch.setChecked(false);
        ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    numChecked++;
                } else {
                    numChecked--;
                }
    
                if (numChecked == 4) {
                    buttonView.setChecked(false);
                    numChecked--;
                    // fourth one selected, show your dialog
                }
            }
        });
    }
    

    You will also need a global variable call numChecked:

    int numChecked = 0;
    

    You will also need to add a .addView(ch) in the loop’s end to add the CheckBoxes to your layout.

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

Sidebar

Related Questions

I have created a User Control with 4 check boxes(server control). I want to
I have created this function to check abecedarian with while loop (A word is
Suppose I have created one jQuery function to check if elements exist or not
I have created a DeclarativeServiceLibrary using VS2010 beta 2, Please check this image of
i have a form created using Visual Basic 2008 in c# i want to
I have List of Checkboxes which i want to create using FOR LOOP .
i have a list of dynamically created check boxes. when the state of the
I have created a gridview with a column of checkboxes. I want the user
I have created a method to check if the keyboard is used in an
I have created an tableview that shows RSSS. I check for internet connection then

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.