Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Movie Night in Android

In the project Movie Night, when I click on one of the genres on my app, another genre off-screen gets clicked too. Fix?

Hi! I'm having a lot of trouble with my genre listview page on my app. When I turn on my app, there is a button that takes you to another page with a list of genres. If I click, for example, "Action," the "War" category off-screen gets clicked too. So when you scroll to War, you see that it is clicked. Why is this happening? And how do I fix it? Please help!

You can get to my project at Github: https://github.com/slim0926/MovieNight

1 Answer

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

This happens because of how ListVIews reuse views. Remember that as each item view is scrolled off the screen, it is reused for one of the new item views that is about to scroll onto the screen. This saves processing and memory to generate the views from scratch which makes for smooth scrolling.

RIght now in your project you are setting the background color of a specific item view when it's tapped. Then, when that item scrolls off the screen, its view is reused and populated with new data. But you aren't doing anything about the background color in the getView() method of your adapter, so it's reusing whatever background color was previously set.

To work around this, you need to keep track of which items are selected or not, and then check it for selection in the getView() method. You want getView() to properly set the background color based on if an item has been selected or not.