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

RecyclerView Object Keeps Un-Checking Itself

So I have a list of objects in a RecyclerView with a string and boolean attribute. The boolean is for checking whether an object is starred or not. I have the 'checking and un-checking the star' part done (I hope):

-RecyclerAdapter-

mImportantImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mImportantImageView.getTag().equals(1)) {
                        mImportantImageView.setTag(2);
                        mImportantImageView.setImageResource(R.drawable.star);
                    } else {
                        mImportantImageView.setTag(1);
                        mImportantImageView.setImageResource(R.drawable.staropen);
                    }
                }
            });

However, when I go and create a new object, the first few objects un-check themselves automatically. Sometimes, it isn't just the first few either, it happens randomly throughout my list.