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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:52:15+00:00 2026-06-07T09:52:15+00:00

I added two check box in the on create method checkBox1 = (CheckBox) findViewById(R.id.checkBox1);

  • 0

I added two check box in the on create method

  checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
  checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
  checkBox1.setOnCheckedChangeListener(this) ; 
  checkBox2.setOnCheckedChangeListener(this) ;

the main function of the check boxes that when ischeck() a picture will be added to the mainlayout and when uncheck the picture will be removed >> I used the code bellow, the first check box is working fine the second check box when I do check it shows the pics and then they I can remove them even with uncheck … where is the wrong in my code ??

   public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

// TODO Auto-generated method stub
if(checkBox1.isChecked())
{ 

    ......
    mapOverlays.add(custom); 
}
else {
    mapOverlays.remove(custom)  ;
}

if (checkBox2.isChecked())
{
    ....

    mapOverlays.add(custom2);
}
else 
{
    mapOverlays.remove(custom2)  ;
}
}
}
  • 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-07T09:52:17+00:00Added an answer on June 7, 2026 at 9:52 am

    You are handling second checkbox checking differently. May be the code should look like this?

    if (checkBox2.isChecked())
    {
        ...
        mapOverlays.add(custom2);
    }
    else
    {
        mapOverlays.remove(custom2);
    }
    

    Upd: if your code looks like in the current edit, then issue is the declaring custom2 variable in the if block. You are deleting not added mapOverlay, but another one declared somewhere else.

    Just replace

    if (checkBox2.isChecked())
    {
        MapItemizedOverlay custom2 = ...
    

    by

    if (checkBox2.isChecked())
    {
        custom2 = ...
    

    Upd2: there is yet another issue with your onCheckedChanged() method. First if-else runs not only on checkBox1 check/uncheck but also on checkBox2 check/uncheck. Same for the second if-else.

    Try to rewrite method:

    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (buttonView.equals(checkBox1)) {
            // first if-else
        } else if (buttonView.equals(checkBox2)) {
            // second if-else
        }
    }
    

    or even better:

    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (buttonView.getId() == R.id.checkBox1) {
            if (isChecked) { 
                ...
                mapOverlays.add(custom);
            } else {
                mapOverlays.remove(custom);
            }
        } else if (buttonView.getId() == R.id.checkBox2) {
            if (isChecked) { 
                ...
                mapOverlays.add(custom2);
            } else {
                mapOverlays.remove(custom2);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created one linear layout and I have added two relative layout. I wish
I've a problem with the ScrollViews in Titanium in an iOS-app: I added two
I have a gridview that displays items details, I added two template fields one
Two new keywords added to the C# 5.0 language are async and await ,
I added to my system-wide /etc/security/limits.conf the following two rows: * soft rtprio 55
I've added a SplitContainer with a horizontal bar between the two panes. I can
I have two models Artist and Painting . I added the following migration and
I have two UIViews, UIView1 and UIView2. UIView2 is being added as a subview
I have two forms in my project, form1 and form2. I have added a
My storyboard seems locked. I have added new labels and imageviews to two different

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.