0

I am using google maps therefore when checking the checkbox some pictures will be added to the layer and the other check box will add different layer... when unchecking the first check box the picture related to it will be removed and also for the same will happen for the second check box.. Now the problem is that when checking the first check box the pics are added and then i do uncheck to the related check box the pics are not removed while the second check box is working fine ?? Help please

I have a button that when I press it a dialog will be shown.. This dialog contains a check boxes. .
I defined the following variables in the class

     CharSequence[] items = {"Layer1", "Layer2"};
     boolean[] itemsChecked = new boolean[items.length];

in the On create method I defined the following

      Button AddLayers = (Button) findViewById(R.id.addlayers) ; 
      AddLayers.setOnClickListener(this) ; 

Then in the action

public void onClick(View v) {
// TODO Auto-generated method stub

 showDialog(0);
}

@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 0:
    return new AlertDialog.Builder(this)
    //.setIcon(R.drawable.red_point)
    .setTitle("Add Layer")


      .setPositiveButton("OK", new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface dialog, int id)
                {
                    SparseBooleanArray CheCked = ((AlertDialog) dialog).getListView().getCheckedItemPositions();
                    if (CheCked.get(0))
                    {
                         ...    
                        mapOverlays.add(custom);
                    }
                    else {
                        mapOverlays.remove(custom);
                    }


                    if (CheCked.get(1))
                    {
                        ......
                        mapOverlays.add(custom2);
                    }
                    else 
                    {
                        mapOverlays.remove(custom2)  ;
                    }



                }
user1413188
  • 91
  • 5
  • 14
  • Can you please go into more detail on the expected behaviour and what you're seeing? Also, where do you populate the AlertDialog's list view? – Iain Jul 11 '12 at 05:39
  • At this point all I can offer is classic debugging advice. You need to bridge the gap between "what do I expect to happen?" and "what is happening?" in order to make the two the same. In this case, the gap between expectation and reality is either that CheCked.get(0) always returns true, or mapOverlays.remove(custom) doesn't do what you want. You have two things to check. First, are you getting into the `mapOverlays.remove(custom)` line? Put some logging in. Second, if that line executes, does it do what you expect it to? Add a button that just does that and see if it works like you expect. – Iain Jul 11 '12 at 06:17
  • Is mapOverlays an Android class type? – The Original Android Jul 11 '12 at 06:30
  • I didnt solve it yet... when I do check for the first one and un check it work fine it add pics and it remove them... then when checking both together, when un checking the first checkbox, the pics are not removed again .. I added a string to be shown if it reaches to that line of code and it did reach but the pics are not removed – user1413188 Jul 11 '12 at 06:30
  • the removing function is working since when I do check and uncheck for the first checkbox without touching the second checkbox it add and remove the pics perfectly – user1413188 Jul 11 '12 at 06:33
  • Is mapOverlays an Android class type? Mapoverlays is an Ovelay item i define it as follow List mapOverlays ; – user1413188 Jul 11 '12 at 06:34

2 Answers2

0

When the check box is ticked your showing some data and when it is unchecked you need to remove those, if it is so try using mapOverlays.clear(); instead of mapOverlays.remove(custom2) ;

Siva K
  • 4,968
  • 14
  • 82
  • 161
  • but I have different customs if I did clear it will remove all of them – user1413188 Jul 11 '12 at 06:43
  • just clear and once again add the custom which you need to show according to the check box.... – Siva K Jul 11 '12 at 06:45
  • this is not efficient... I just want to remove the layer that I un-checked ... I think the problem that it checks the first check box if it is checked it will do also the else for the second checkbox ... I want to separate the check box when checking the values – user1413188 Jul 11 '12 at 06:51
  • I will add more layers in the future because of that I dont want to re-add the layers when ever I clear one only – user1413188 Jul 11 '12 at 06:52
0

Hello all I found the solution... It was because the definition of the custom was inside the if(CheCked.get(0)) ... it should be in the Oncreat()

because defining the custom in the if (CheCked.get(0)) will create a new custom every time we check the check-box and the first custom when we want to delete i t is lost because a new one was defined

Thanks for all who tried to help, I am really thankful

user1413188
  • 91
  • 5
  • 14