title: Display blank item in grid view
body: <p>On home scree of application, how to display the menu which is similar to android menu but no items needs to be displayed in specific cells. Considering grid of 3 x 3, five items only needs to be displayed at (Row, Col): [0,1], [1,0], [1,1], [1,2], [2,1].</p>
  
  <p>We have tried GridView and set visibility to GONE (convertView.setVisibility(View.GONE);) for items which need not be displayed. Following this, item is not displayed in grid but when user browses through blank item using up and down keys or click directly on blank item, that icon is hihglighted and selected as if it is blank item in grid. We want as it is blank it should not repond to user events neither highlighted not selected.</p>
  
  <p>Code for Grid View:</p>
  
  <pre><code>package org.XXX;
  
  import android.app.Activity;
  import android.content.Context;
  import android.content.Intent;
  import android.graphics.BitmapFactory;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.BaseAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class XXXActivity extends Activity {
      GridView MyGrid;
  
      @Override
      public void onCreate(Bundle savedInstanceState){
          super.onCreate(savedInstanceState);
          setContentView(R.layout.maingrid);
          MyGrid = (GridView)findViewById(R.id.MyGrid);
          MyGrid.setAdapter(new ImageAdapter(this));
  
  
          MyGrid.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position, long arg3) {
                  Toast.makeText(arg0.getContext(), position + " selected", Toast.LENGTH_LONG).show();
  
                  switch(position) {
                  case 0:break;
                  case 1:
                      //Browse
                      Intent newIntent = new Intent(XXXActivity.this, YYYListItemIcons.class);
                      startActivity(newIntent);
                      break;
                  case 2:break;
                  case 3:
                      //Saved Searches
                      newIntent = new Intent(XXXActivity.this, ZZZListItemIcons.class);
                      startActivity(newIntent);
                      break;
                  case 4:
                      //Sign in
                      break;
                  case 5:
                      //Reminders
                      break;
                  case 6:break;
                  case 7:
                      //Sign up
                      break;
                  case 8:break;
                  }
              }
  
          });
  
          //onSearchRequested(); //to open search by default
      }
  
  
      public class ImageAdapter extends BaseAdapter
      {
          Context MyContext;
  
          public ImageAdapter(Context _MyContext)
          {
              MyContext = _MyContext;
          }
  
          @Override
          public int getCount()
          {
              return 9;
          }
  
          public View getView(int position, View convertView, ViewGroup parent) {
  
              ViewHolder holder;
              LayoutInflater mInflater = LayoutInflater.from(MyContext);
  
              if (convertView == null) {
                  convertView = mInflater.inflate(R.layout.grid_item, null);
                  holder = new ViewHolder();
                  holder.text = (TextView) convertView.findViewById(R.id.grid_item_text);
                  holder.icon = (ImageView) convertView.findViewById(R.id.grid_item_image);
                  convertView.setTag(holder);
              } else {
                  holder = (ViewHolder) convertView.getTag();
              }
  
              // Bind the data efficiently with the holder.
              holder.text.setText(getTextId(position));
              holder.icon.setImageBitmap(BitmapFactory.decodeResource(MyContext.getResources(), getIconId(position)));
              if(getIconId(position) == R.drawable.nothing) {
                  convertView.setVisibility(View.GONE);
              }
              return convertView;
          }
  
          @Override
          public Object getItem(int arg0) {
              return arg0;
          }
  
          @Override
          public long getItemId(int arg0) {
              return arg0;
          }
  
          private int getIconId(int position) {
              int iconImages[] = {
                      R.drawable.nothing,
                      R.drawable.browse,
                      R.drawable.nothing,
                      R.drawable.saved_searches,
                      R.drawable.sign_in,
                      R.drawable.reminders,
                      R.drawable.nothing,
                      R.drawable.sign_up,
                      R.drawable.nothing
              };
              return iconImages[position];
          }
  
          private int getTextId(int position) {
              int iconNames[] = {
                      R.string.nothing,
                      R.string.browse,
                      R.string.nothing,
                      R.string.saved_searches,
                      R.string.sign_in,
                      R.string.reminders,
                      R.string.nothing,
                      R.string.sign_up,
                      R.string.nothing
              };
              return iconNames[position];
          }
  
      }
  
      static class ViewHolder {
          TextView text;
          ImageView icon;
      }
  
  }
  </code></pre>
  
  <p>GridLayout:</p>
  
  <pre><code>&lt;GridView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/MyGrid"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="center"
      android:padding="5dp"
      android:verticalSpacing="5dp"
      android:horizontalSpacing="20dp"
      android:numColumns="auto_fit"
      android:columnWidth="60dp"
      android:stretchMode="columnWidth"
      android:gravity="center"&gt;
  &lt;/GridView&gt;            
  </code></pre>
  
  <p>PerItemIconLayout in Grid:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/GridItem"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:orientation="vertical"
     android:gravity="center_horizontal"&gt;
  
     &lt;ImageView android:id="@+id/grid_item_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"&gt;
     &lt;/ImageView&gt;
  
     &lt;TextView android:id="@+id/grid_item_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:gravity="center_horizontal"
        android:textColor="#FFFFFF"&gt;
     &lt;/TextView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>