Once I delete an object from an array, I need to delete it from another array at the same time. How? [closed]
Ive got an app containing contact list, similar to Contacts application. I have all the objects in an array, but I have another array for favourite contacts, which is displayed in another tab. The problem is that once I delete an objects from my contacts array, it stays in the favourites array. Any ideas how can this be solved? It would help a lot. Thanks
As the comments said, your language and array structure would be useful, but I'll try and answer from a "algorithm" perspective.
Your "Favourites" should contain the same objects as in your Contact list (and I assume that object has an ID. If it doesn't, put one in). From there you can say "if I delete from Favourites, simply remove that object from the array". Otherwise, "if I delete from the 'Contacts list' then iteratively remove all the equivalent objects from the other arrays".
Alternatively, if your "Favourites" array simply holds the ID of the contact (and to display it you retrieve the object from the Contact list), then similarly you can delete the number.
Hope this helps, and when you clarify your question more, I'm sure someone will give you a more efficient answer ;)
精彩评论