Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Noah Schill
10,020 Pointsfailing the second task
When I add set the mInvite visibility ti View.INVISIBLE in the else block, it fails the second task. Why is this?
import android.app.Activity;
import android.os.Bundle;
import android.view.ListView;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.TextView;
public class InviteActivity extends Activity {
/*
* Some code has been omitted for brevity!
*/
public MenuItem mInviteMenuItem;
public GridView mGridView;
public TextView mEmptyTextView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player_grid);
mGridView = (GridView)findViewById(R.id.gridView);
mGridView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
mGridView.setOnItemClickListener(mOnItemClickListener);
}
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

Harry James
14,780 PointsHey Noah!
The problem actually lies in the first section. You want to check if the checked item count is greater than 0, not equal to 0.
Then, your code should pass the challenge :)
Hope it helps!
Ivan Sued
5,969 PointsIvan Sued
5,969 PointsI agree that it should work with your suggestion but i do not seem to get it working either with this logic.
if (mGridView.getCheckedItemCount() > 1){ mInviteMenuItem.setVisibility(View.VISIBLE); }
or using if (mGridView.getCheckedItemCount() > 1){ mInviteMenuItem.setVisible(true); }
Harry James
14,780 PointsHarry James
14,780 PointsHey Ivan Sued! You want to do it so that the if statement runs if the item count is greater than 0, you're trying to do greater than 1 :)
Ivan Sued
5,969 PointsIvan Sued
5,969 PointsThanks Harry James . You are correct the 0 is what I needed. I think the problem is a bit confusing since the first question says more than 1 item selected but the second task is requiring at least one.
Noah Schill
10,020 PointsNoah Schill
10,020 PointsThank you Ivan and Harry! Helped me out a tonne!
Anthony Attard
43,915 PointsAnthony Attard
43,915 PointsVery confusing as 1 passes the first task but fails the second one.
Harry James
14,780 PointsHarry James
14,780 PointsHey Anthony Attard.
I've just gave this a go and it's true, using greater than 1 will pass the first challenge, although it should not.
I'll tag Ben Jakuben here to see if this challenge could be updated to avoid such confusion.