graphic selected

1773
1
06-03-2014 06:38 AM
AhmedAlqusaibi
New Contributor
Hello,

I used the sample code for selected graph
ArrayList idList = new ArrayList();
public void featureHit(com.esri.toolkit.overlays.HitTestEvent event) { 
      // get hit graphics 
 List<Feature> hitGraphics = event.getOverlay().getHitFeatures(); 
      myGraphicsLayer = (GraphicsLayer) event.getOverlay().getLayer(); 
      for (Feature graphic : hitGraphics) { 
        id = (int) graphic.getId(); 
        if (myGraphicsLayer.isGraphicSelected(id)) { 
          // if graphic is selected in the layer, unselect it 
          myGraphicsLayer.unselect(id); 
          } else { 
          // otherwise select graphic in the layer 
          myGraphicsLayer.select(id);
          idList.add(id);
        } 
      }  
    }


So, I'm recording all the ID's for the graph in arraylist and I've action button connected Action Listener which perform this code

for(int i=0;i<=idList.size();i++)
                {
                    if (myGraphicsLayer.isGraphicSelected(id)) 
                    {
                        System.out.print(id);
                        myGraphicsLayer.unselect(id); 
                    }
                }


The problem is, it's only unselected the last ID graph, the others unaffected. So what do you suggest? I'm using 10.2.3
0 Kudos
1 Reply
EliseAcheson1
Occasional Contributor
If that's the exact code you're using then (in second code snippet) I don't see where you are using the 'i' from your for loop?

Also note that GraphicsLayer has methods to deselect all selected graphics in the layer (clearSelection()) and to get the IDs of all selected graphics (getSelectionIDs()), so those might be handy depending on what you're doing.

~elise
0 Kudos