mattcoker
mattcoker

Reputation: 169

After leaving and returning to Activity, Listview shows multiples of items

I currently click a button from MainActivity which takes me to HotSpotsActivity, displaying a list of sports team names in alphabetical order. Upon pressing Back to go to the MainActivity (and even if I hit home and resume the app), HotSpotsActivity redownloads the data and displays it below the original items, so I will have as follows: Team A, B, C, D, E, Team A, B, C, D, E.

If I back up and try again, it displays a 3rd copy, then a 4th, and so on.

The confusing thing is that I already have a related activity (EventsActivity) that has no issue with this, and has a clear view when I resume the EventsActivity and then redownloads the data. All of the code relating to the downloading of data is nearly identical, can someone please tell me what I am missing?

I have included the EventsActivity and related EventsAdapter, both of which work, and the HotSpotsActivity and related HotSpotsAdapter, which do not work.

DOES WORK: http://pastebin.com/mG5FVnbx http://pastebin.com/aXEw9T8S

DO NOT WORK: http://pastebin.com/FNPKyisB http://pastebin.com/F00w4gUn

Upvotes: 2

Views: 491

Answers (2)

Daisy Holton
Daisy Holton

Reputation: 519

You are most likely adding the items when the activity starts, even when they are already in the listview. Check your code.

Upvotes: 0

Stratus_Hunter
Stratus_Hunter

Reputation: 301

Your arraylist in hotspots is static. This means it exists constantly and you are never calling clear(). So when you call add() in the json parsing you are just appending over and over again. It looks like your other array in events is not static so it is a new array every time you create your activity. Hope this helps :)

Upvotes: 2

Related Questions