View Single Post
Old 05-18-2012, 04:54 PM   PM User | #5
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
I don't think it is an android thing or even a custom class thing... could be wrong- but here is my take on it...
you are essentially saying this
Quote:
I have a 'list of stuff' ... I am doing things with this 'list of stuff', and at some point i would like the ability to remove things from this 'list of stuff'.
i have no clue how your list is set up, but if you are actively using it in a loop, you can't remove it from there or it would mess up the loop.
so... pardon the C#/Java hybrid
Code:
public class Demo extends Activity{
@Override
   public void onCreate(Bundle savedinstancestate){
      super.onCreate(savedinstancestate);
      setContentView(R.layout.main);

      // and now you have your list
      List<OverlayItem> _overlaylist = new List<OverlatItem>();
      // then you fill your list
      fillList();
      // then loops
      foreach(OverlayItem _o in _overlaylist)
      {
           if(something == something)
              _overlaylist.Remove(_o);
       }
       // or...
       for(int i=0; i < _overlaylist.length; i++)
       {
            if(something == something)
              _overlaylist.Remove.indexof(i);
       }
     
    }

    private void fillList(){...};
that won't work... I don't think it would compile, and if it did you are at high risk of throwing an error at runtime. you need to change up the logic to maybe something like...

Code:
public class Demo extends Activity{
@Override
  
   List<OverlayItem> _overlaylist = new List<OverlatItem>();
   // note that the list is now a global variable

   public void onCreate(Bundle savedinstancestate){
      super.onCreate(savedinstancestate);
      setContentView(R.layout.main);

      // then you fill your list
      fillList();
      while(!something)
      {
         scanlist();
         Thread.sleep(2000);
      }
    }
    
    private void scanlist()
    {
         // note: you can do this in the 'main' void but I think it's best to break things
         // into functions- also once you end this function your temp list will be disposed of
         List<OverlayItem> tmpList = new List<OverlayItem>();
         foreach(OverlatItem _o in _overlaylist)
         {
            if(something == something)
              tmpList.Add(_o);
         }
         // now that you are out of the list loop...
         foreach(OverlayItem _o in tmpList)
         {
            _overlayitemlist.Remove(_o);
         }
    }

    private void fillList(){...};
does that make any sense or help?
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote