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

J Smillie
PLUS
J Smillie
Courses Plus Student 40,123 Points

Can someone please point out what is wrong with this answer?

Challenge Task 5 of 5 Implementing Designs for Android

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;
    public TextView mEmptyTextView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.player_grid);


      mEmptyTextView = (TextView)findViewById(android.R.id.empty);


      mGridView.setEmptyView(mEmptyTextView);

        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);
          }



        }       
    };
}

This is my answer

mGridView.setEmptyView(mEmptyTextView);

3 Answers

try moving it down after you actually set the gridView using findViewById. you currently have it above the line that sets mGridView.

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.player_grid);


      mEmptyTextView = (TextView)findViewById(android.R.id.empty);

        mGridView = (GridView)findViewById(R.id.gridView);

        mGridView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        mGridView.setOnItemClickListener(mOnItemClickListener);

        mGridView.setEmptyView(mEmptyTextView);