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 trialAdlight Sibanda
5,701 Pointsgrid view
Finally, set this view as the empty view for mGridView.
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(); <----- MY EMPTY VIEW
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);
mEmptyTextView = (TextView) findViewById(android.R.id.empty);
}
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
James Simshaw
28,738 PointsHello,
You're close to completing this challenge. Just a few things you need to do to finish it.
First, you need to remove the text <----- MY EMPTY VIEW. If you want that to be a comment use //<----- MY EMPTY VIEW. "//" denotes a single line comment so anything after it on the line will not be read by the compier.
Second, your mGridView(); should be defining a variable so you want to remove the parenthesis.
At this point, if you were to submit it, you would actually get a very helpful bummer message. Which all you need to do now is use the setEmptyView(View v) of your GridVIew to set mEmptyTextView as the empty view. Please let us know if you need more assistance and we will try to help further. Also, if you do need assistance, please provide updated code so we can assist you from where you currently are at.