title: Disabling onClick for selected items in GridView Android
body: <p>I would like to know how to disable click for a set of items in <code>Gridview</code>.</p>
  
  <p>This is the class:</p>
  
  <pre><code>public class LevelSelectActivity extends Activity {
  
  public GridView gridView;
  public TextView Easy;
  public TextView Medium;
  public TextView Hard;
  public Button mBackButton;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_level_select);
  
      Easy = (TextView) findViewById(R.id.EasyText);
      Easy.setTypeface(ApplicationServices.typeFaceDoubleBlast);
      Medium = (TextView) findViewById(R.id.MediumText);
      Medium.setTypeface(ApplicationServices.typeFaceDoubleBlast);
      Hard = (TextView) findViewById(R.id.HardText);
      Hard.setTypeface(ApplicationServices.typeFaceDoubleBlast);
  
      mBackButton = ( Button ) findViewById ( R.id. BackButton );
      mBackButton.setOnClickListener(mBack_Clicked);
  
      gridView = (GridView) findViewById(R.id.LevelSelectGrid);
      gridView.setAdapter(new ImageAdapter(this));
      gridView.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                  int position, long id) {
  
              // Sending image id to FullScreenActivity
              Intent i = new Intent(getApplicationContext(), DoubleBlastGameActivity.class);
              // passing array index
              if(position &gt;= 0 &amp;&amp; position &lt; 4)
              {
                  i.putExtra("level", 1);
              }
              else if(position &gt;= 4 &amp;&amp; position &lt; 8)
              {
                  i.putExtra("level", 2);
              }
              else if(position &gt;= 8 &amp;&amp; position &lt; 12)
              {
                  i.putExtra("level", 3);
              }
  
              startActivity(i);
          }
      });
  }
  
  public View.OnClickListener mBack_Clicked = new View.OnClickListener() {
  
      public void onClick(View v) {
  
          Intent intend = new Intent(getBaseContext(), MainMenuActivity.class );
          startActivity(intend);
      }
  };
  public class ImageAdapter extends BaseAdapter {
  
      private Context context;
      public Integer[] mLevelIcon;
      public String[] mLevelId;
  
      public ImageAdapter(Context contextTemp) {
          this.context = contextTemp;
          mLevelId = new String[12];
          mLevelIcon = new Integer[12];
          for (int i = 0; i &lt; mLevelId.length; i++) {
              mLevelId[i] = Integer.toString(i + 1);
              if(i + 1 &lt;= ApplicationServices.gameConfigStructure.lastCompletedLevelInt )
              mLevelIcon[i] = R.drawable.levelbutton;
              else
              mLevelIcon[i] = R.drawable.lock;
          }
  
      }
  
      public int getCount() {
          // TODO Auto-generated method stub
          return mLevelId.length;
      }
  
      public Object getItem(int position) {
          // TODO Auto-generated method stub
          return null;
      }
  
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return 0;
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
  
          LayoutInflater inflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          View gridView;
  
          if (convertView == null) {
              gridView = new View(context);
  
              gridView = inflater.inflate(R.layout.level_button, null);
  
              TextView textview = new TextView(context);
              textview = (TextView) gridView.findViewById(R.id.LevelID);
              textview.setText(mLevelId[position]);
              textview.setTypeface(ApplicationServices.typeFaceDoubleBlast);
  
              if(position &gt;= ApplicationServices.gameConfigStructure.lastCompletedLevelInt )
              {
                  textview.setVisibility(View.INVISIBLE);
              }
  
              LevelSelectButton button = new LevelSelectButton(context);
              button = (LevelSelectButton) gridView
                      .findViewById(R.id.levelSelectButton1);
              button.setImageResource(mLevelIcon[position]);
  
          } else {
              gridView = convertView;
          }
          return gridView;
      }
  
  }
  }
  </code></pre>
  
  <p>And this the screen shot for the Level Select Screen:</p>
  
  <p><img src="https://i.stack.imgur.com/5CQhZ.jpg" alt="enter image description here"></p>
  
  <p>As you can see the first level is unlocked and ideally I would prefer only the unlocked levels to be click able. But currently it is allowing to enter any level.</p>
  
  <p>How do I turn off the click for the locked levels?</p>