title: ArrayOut of Bound exception in Android while working with grid view
body: <pre><code>@Override
  public View getView(final int position, View view, ViewGroup parent) {
       view = _lInflater.inflate(R.layout.all_apps_checked_item, null);
       CheckBox chkUhkItem = (CheckBox) view.findViewById(R.id.all_apps_cb);
       chkUhkItem.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
               _iCheckBoxClick.onCheckCliked(isChecked,_apps.get(position).packageName,position);
           }
        });
        return view;
  }
  </code></pre>
  
  <p>And my public interface is </p>
  
  <pre><code>public interface ICheckBoxClick{
      void onCheckCliked(boolean isChecked,String packageName,int pos);
  }
  </code></pre>
  
  <p>And my implementation is for ICheckBoxClick is:</p>
  
  <pre><code>//Apps Seletion Dialog
  public void showSeletionAppsDialog(Context actityCtx,
          final String cat_name, final IAddSubItemsClick iAddSubItemsClick) {
      final ArrayList&lt;String&gt; selected = new ArrayList&lt;String&gt;();
      final Dialog dialog = new Dialog(actityCtx);
      dialog.setTitle("Select Apps =&gt;" + cat_name);
      dialog.setContentView(R.layout.all_apps_grid);
      GridView appsGrid = (GridView) dialog.findViewById(R.id.all_apps);
      ICheckBoxClick icheckBoxClick = new ICheckBoxClick() {
  
          @Override
          public void onCheckCliked(boolean isChecked, String pkgName, int pos) {
              if (isChecked) {
                  selected.add(cat_name + "," + pkgName);
              } else {
                  selected.remove(pos);
              }
          }
      };
      appsGrid.setAdapter(new AllAppsSelectionAdapter(actityCtx,
              icheckBoxClick));
  }
  </code></pre>
  
  <p><code>Selected.remove(pos)</code> is throwing Array out of bound exception.</p>
  
  <pre><code>12-30 12:59:18.106: E/AndroidRuntime(13028): java.lang.IndexOutOfBoundsException: Invalid index 7, size is 1
  12-30 12:59:18.106: E/AndroidRuntime(13028):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
  12-30 12:59:18.106: E/AndroidRuntime(13028):    at java.util.ArrayList.remove(ArrayList.java:403)
  </code></pre>
  
  <p>From the above logs I understood that size of ArrayList is only 1 and you are trying to remove &amp; element. Hence arrayOutOfBoundException. I don't have better solution to fix this.</p>