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 Implementing Designs for Android Updating Other GridViews Updating the Recipients Activity

Jacob Bergdahl
Jacob Bergdahl
29,119 Points

Android code challenge not working properly

Either I've gone blind or this challenge doesn't work properly. Task 2 is to set the variable to View.VISIBLE, which I've done and which passes, while task 3 is to add an else-statement in which the variable is set to View.INVISIBLE, which I've also done, however no matter what I try, it doesn't pass.

InviteActivity.java
// unimportant code emitted
    public OnItemClickListener mOnItemClickListener = new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            // Start by adding code in here!
          if (mGridView.getCheckedItemCount() >= 0) 
            mInviteMenuItem.setVisibility(View.VISIBLE);
          else 
            mInviteMenuItem.setVisibility(View.INVISIBLE);

        }       
    };
}

1 Answer

Jacob Bergdahl
Jacob Bergdahl
29,119 Points

Ah, never mind, I solved it. The equal-sign is why it failed. The compiler didn't realize my mistake, and I was equally blind to it, heh.

The correct answer is:

if (mGridView.getCheckedItemCount() > 0) 
       mInviteMenuItem.setVisibility(View.VISIBLE);
else 
       mInviteMenuItem.setVisibility(View.INVISIBLE);