Kevin,

You have a simple programming error in your code.

When you remove an entry, the array shrinks, and positions of items that you haven't checked yet shift down by one. Then when the for-loop increments the current position (variable "i"), it actually skips over the next entry, since that entry and all the others shifted.

You can either rewrite your loop like this:

                 for (int i = 0; i<  Name.size();*/* nothing here */*) {
                         if (Name.get(i)== name){
                                 Name.remove(i);
                                 Number.remove(i);
                                 Address.remove(i);
                                 Email.remove(i);
                         }*  else { i++; }*
                 }
Or iterate the array back-to-front (from size() - 1 to 0), so the index is not affected by position shifts.

-- Kostya

07.12.2010 11:47, Zarah ?????:
Instead of getting the ID, maybe you should get the actual string
associated with that ID.  Then loop through all entries on your
ArrayList of Names, and then compare using
Name.get(i).equals(nameSelected).  If this returns true, then delete.

Remember to make a character-by-character comparison on Strings,
use .equals and not ==.


Hope this helps.


-Zarah.



On Dec 7, 12:04 pm, Kevin Anthony<kevin.s.anth...@gmail.com>  wrote:
I'm not trying to clear the list
I'm trying to remove all names that are equal to the name you asked to
remove.

you have a list of
bob
bob
tom
tim
sam
suzie

you click on one bob, both bobs get removed

On Dec 6, 7:28 pm, Bret Foreman<bret.fore...@gmail.com>  wrote:







This is simpler:
while( Name.size()>  0 ) {
   Name.remove(0);
}
On Dec 6, 3:59 pm, Kevin Anthony<kevin.s.anth...@gmail.com>  wrote:
i have a List<String declared like this:
private static List<String>  Name = new ArrayList<String>();
private static List<String>  Number = new ArrayList<String>();
private static List<String>  Address = new ArrayList<String>();
private static List<String>  Email = new ArrayList<String>();
and i'm trying to loop threw and delete them when a user longclicks on
them and clicks delete
here's the delete code:
public void deleteName(long id){
                 String name = Name.get((int)id);
                 for (int i = 0; i<  Name.size();i++) {
                         if (Name.get(i)== name){
                                 Name.remove(i);
                                 Number.remove(i);
                                 Address.remove(i);
                                 Email.remove(i);
                         }
                 }
                 return;
         }
however, it only deletes the entry you click on, not all entries, i've
done some log outputting and the Entries all look the same to my eye,
even capilization.
What am i doing wrong?
Thanks
Kevin A


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to