title: How to check checkbox on clicking an image?
body: <p>I have created a gridview and added a checkbox in it.On clicking on checkbox grid view item which are image view with textview get selected.</p>
  
  <p>But I want to check the checkbox on tap of grid view item.</p>
  
  <p>This my MainActivity</p>
  
  <pre><code> public class MainActivity extends Activity {
  
              GridView gridview;
  
  
              @Override
              protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.activity_main);
  
  
  
                  gridview = (GridView) findViewById(R.id.mainGrid);
  
                  gridview.setAdapter(new ImageAdapter(MainActivity.this));
  
                  gridview.setOnItemClickListener(new OnItemClickListener() {
  
                      @Override
                      public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position,
                              long id) {
                          // TODO Auto-generated method stub
          //
          //
  
  
  
                          ImageAdapter.holder.ItemCheck.setId(position);
                          ImageAdapter.holder.ItemCheck.setOnClickListener(new OnClickListener() {
  
                              public void onClick(View v) {
                                  // TODO Auto-generated method stub
  
                                  //ImageAdapter.holder.ItemCheck.setChecked(true);
                                  Toast.makeText(MainActivity.this, "Itemclicked" ,Toast.LENGTH_LONG).show();
                              }
                          });
                          Toast.makeText(
                                  MainActivity.this, "Itemclicked", Toast.LENGTH_SHORT).show();
  
                      }
                  });
  
                  };
  
  
              @Override
              public boolean onCreateOptionsMenu(Menu menu) {
                  // Inflate the menu; this adds items to the action bar if it is present.
                  getMenuInflater().inflate(R.menu.main, menu);
                  return true;
              }
  
          }
  </code></pre>
  
  <p>This is my AdapterClass</p>
  
  <pre><code>    public class ImageAdapter extends BaseAdapter{
  
          private Context mContext;
          public static ViewHolder holder;
  
  
  
          public ImageAdapter(Context c) {
              mContext = c;
          }
  
  
  
          @Override
          public int getCount() {
              return mThumbIds.length;
          }
  
          @Override
          public Object getItem(int position) {
              return null;
          }
  
          @Override
          public long getItemId(int position) {
              return 0;
          }
  
  
          public boolean areAllItemsEnabled(){
              return true;
          }
  
          @Override
          public boolean isEnabled(int position) {
              // TODO Auto-generated method stub
              return true;
          }
  
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              // TODO Auto-generated method stub
  
              //ViewHolder holder;
              View myView = convertView;
              ImageView imageView;
              if (convertView == null) {  // if it's not recycled, initialize some attributes
                  //Inflate the layout
  
                   holder = new ViewHolder();
                  imageView = new ImageView(mContext);
  
                  imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
                  imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                  imageView.setPadding(8, 8,8, 8);
  
  
  
  
                  LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);           
                  myView = inflater.inflate(R.layout.grid_items_ontap, null);
  
                   holder.ItemCheck = (CheckBox) myView.findViewById(R.id.itemCheckBox);
                      myView.setTag(holder);
              }else{
                  holder = (ViewHolder) myView.getTag();
              }
      //      holder.ItemCheck.setId(position);
      //      holder.ItemCheck.setOnClickListener(new OnClickListener() {
      //
      //          public void onClick(View v) {
      //              // TODO Auto-generated method stub
      //              Toast.makeText(mContext, "Itemclicked" ,Toast.LENGTH_LONG).show();
      //          }
      //      });
  
  
                  // Add The Image!!!           
                  ImageView iv = (ImageView)myView.findViewById(R.id.grid_item_image_OnTap);
                  iv.setImageResource(mThumbIds[position]);
  
  
                  // Add The Text!!!
                  TextView tv = (TextView)myView.findViewById(R.id.grid_item_text_onTap);
                  tv.setText(names[position] );
  
  
                  holder.ItemCheck.setChecked(isEmpty());
                  holder.id = position;
  
  
  
              return myView;
          }
  
  
  
  
  
              public class ViewHolder {
  
                  public CheckBox ItemCheck;
                  int id;
              }
  
  
  
          private String[] names={"ab","cd","ef","gh","ij","kl","mn","","","","","","",""};
  
          private Integer[] mThumbIds = {
                  R.drawable.car, R.drawable.car,
                  R.drawable.car, R.drawable.car,
                  R.drawable.car,R.drawable.car,R.drawable.car,R.drawable.car, R.drawable.car,
                  R.drawable.car, R.drawable.car,
                  R.drawable.car,R.drawable.car,R.drawable.car
          };
  
      }
  </code></pre>
  
  <p>Gridview.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/gridlayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".MainActivity" &gt;
  
      &lt;GridView
          android:id="@+id/mainGrid"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:horizontalSpacing="0dp"
          android:numColumns="3"
          android:clickable="true"
          android:stretchMode="columnWidth"
          android:verticalSpacing="0dp" &gt;
      &lt;/GridView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>griditems.xml file</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/GridItem"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@android:color/transparent"
      android:orientation="vertical" &gt;
  
      &lt;ImageView
          android:id="@+id/grid_item_image_OnTap"
          android:layout_width="100dp"
          android:layout_height="100dp" &gt;
      &lt;/ImageView&gt;
  
      &lt;TextView
          android:id="@+id/grid_item_text_onTap"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:gravity="center_horizontal"
          android:text="TextView"
          android:textColor="@android:color/black" &gt;
      &lt;/TextView&gt;
  
      &lt;CheckBox
          android:id="@+id/itemCheckBox"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:layout_alignParentTop="true"
          android:button="@drawable/custom_checkbox"
          android:checked="true"
          android:visibility="visible"
          android:focusable="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Please suggest me.I m new to android and I got stuck here.</p>
  
  <p>Thanks</p>