title: Delete item from gridview
body: <p>I know that here are many answers how to delete items, but I can't make it work. It show errors. Can you look? I added in adapter remove(position), but I think it works wrongly.
  So I want after using <code>onItemLongClickListener</code> to delete file and its thumbnail too.</p>
  
  <p>Main:</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      final GridView grid = (GridView) findViewById(R.id.gridview);
      final ThumbnailAdapter thumbnails = new ThumbnailAdapter(this);
      grid.setAdapter(thumbnails);
      grid.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener(){
          @Override
          public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View v, int position,
                      long id) {
  
                  final String imgPath = thumbnails.getImagePath(position);
                  File file = new File(imgPath);                  
                   file.delete();
                   thumbnails.remove(position);
                   thumbnails.notifyDataSetChanged();
                   grid.invalidateViews();
                   grid.setAdapter(thumbnails);
                  return true;
  
  
              }
      });
  </code></pre>
  
  <p>Adapter:</p>
  
  <pre><code>public class ThumbnailAdapter extends BaseAdapter {
  
  // Context required for performing queries
  private final Context mContext;
  
  // Cursor for thumbnails
  private final Cursor cursor;
  private final int imgId;
  private final int imgData;
  private final int count;
  
  public ThumbnailAdapter(Context c) {
      this.mContext = c;
  
      // Get list of all images, sorted by last taken first
      final String[] projection = {
              MediaStore.Images.Media._ID,
              MediaStore.Images.Media.DATA
      };
      cursor = mContext.getContentResolver().query(
              MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
              projection,
              null,
              null,
              MediaStore.Images.Media.DATE_TAKEN + " DESC"
      );
      imgId = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
      imgData = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      count = cursor.getCount();
      Log.d("ThumbnailAdapter", count + " images found");
  }
  @Override
  public int getCount() {
      return count;
  }
  @Override
  public Object getItem(int position) {
      return position;
  }
  @Override
  public long getItemId(int position) {
      return position;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      ImageView imageView;
      if (convertView == null) {  // if it's not recycled, initialize some attributes
          imageView = new ImageView(mContext);
      } else {
          imageView = (ImageView) convertView;
      }
      cursor.moveToPosition(position);
      final Bitmap thumbnail = MediaStore.Images.Thumbnails.getThumbnail(
              mContext.getContentResolver(),
              cursor.getInt(imgId), 
              MediaStore.Images.Thumbnails.MICRO_KIND,
              null
      );
      imageView.setImageBitmap(thumbnail);
      Log.d("ThumbnailAdapter", "render: " + cursor.getString(imgData));
      return imageView;
  
  }
  
  public String getImagePath(int position) {
      cursor.moveToPosition(position);
      return cursor.getString(imgData);
  }
  public void remove(int position) {
      remove(position);
      notifyDataSetChanged();
  
  }
  </code></pre>
  
  <p>}</p>