title: Android Where to call changecursor?
body: <p>I have a custom SimpleCursorAdapter with a getView like this:</p>
  
  <pre><code>public View getView(int position, View convertView, ViewGroup parent) { 
      //this.changeCursor(c); tried this didn't work.
      this.c.moveToPosition(position);
      int urlCol = c.getColumnIndex("url");
      final String url = c.getString(urlCol);
      //other code stuff.
      imageDownloader.download(url, thumbnail, rowId, db,pb);
  </code></pre>
  
  <p>The imageDownloader calls an update on the DBAdapter but the c.getString(urlCol) still gives me the previous value. I tried putting changeCursor at the position above but I still got the same value. Where exactly should I be calling this? Thanks!</p>
  
  <p>I actually don't want the ListVIew to redraw I just want to get the latest data into the cursor. I'm passing in my imageview and url into the ImageDownloader class to download the image, set the bitmap to the imageview and update the database. I noticed the cursor was not updated as the getView method returns me the same data.</p>
  
  <p>This is my custom simplecursoradapter declaration. getview is mentioned above.</p>
  
  <pre><code>public class MessagesCursorAdapter extends SimpleCursorAdapter {
  
  private final ImageDownloader imageDownloader = new ImageDownloader();
  </code></pre>
  
  <p>ImageDownloader class</p>
  
  <pre><code>public void download(String url, ImageView imageView, int rowId,
          TestDbAdapter db,ProgressBar pb) {
  
  //url can be a http:// or /mnt/sdcard/mnt/ etc etc 
  //some lenghty code to check if it exists physically on the phone. else....
  forceDownload(url, imageView, rowId, db,pb);
  
  private void forceDownload(String url, ImageView imageView, int rowId,
          TestDbAdapter db,ProgressBar pb) {
  
      BitmapDownloaderTask task = new BitmapDownloaderTask(imageView, rowId,
              db,pb);
  </code></pre>
  
  <p>AsyncTask class in the ImageDownloader class</p>
  
  <pre><code>class BitmapDownloaderTask extends AsyncTask&lt;String, Void, Bitmap&gt; {
      private String url;
      private int rowId;
      private TestDbAdapter db;
      private ProgressBar pb;
      private final WeakReference&lt;ImageView&gt; imageViewReference;      
      public BitmapDownloaderTask(ImageView imageView, int rowId,
              TestDbAdapter db,ProgressBar pb) {
          imageViewReference = new WeakReference&lt;ImageView&gt;(imageView);
          this.rowId = rowId;
          this.db = db;           
          this.pb = pb;
      }
  
  
      @Override
      protected void onPreExecute() {
          // TODO Auto-generated method stub
          pb.setVisibility(View.VISIBLE);
      }
  
      @Override
      protected Bitmap doInBackground(String... params) {         
          url = params[0];
          return downloadBitmap(url);
      }
  
      @Override
      protected void onPostExecute(Bitmap bitmap) {
  
          if (isCancelled()) {
              bitmap = null;
          }
  
          if (imageViewReference != null) {
              ImageView imageView = imageViewReference.get();
              BitmapDownloaderTask bitmapDownloaderTask = getBitmapDownloaderTask(imageView);
  
              if ((this == bitmapDownloaderTask)) {
                  int pos = url.lastIndexOf("/");
                  String fileName = url.substring(pos, url.length());
                  System.out.println(fileName);
  
                  String extLoc = Environment.getExternalStorageDirectory()
                          + "/Test";
  
                  File folder = new File(extLoc);
                  if (!folder.exists()) {
                      folder.mkdir();
                  }
  
                  try {
                      FileOutputStream out = new FileOutputStream(extLoc
                              + fileName);
  
  
                      boolean result = db.updateMessageUrl(rowId, extLoc + fileName);
  //should update cursor here, purpose is to change the url link to a physical location on the phone.
  
                      bitmap.compress(Bitmap.CompressFormat.JPEG, 95, out);
  
                      BitmapFactory.Options options = new BitmapFactory.Options();
                      options.inTempStorage = new byte[24 * 1024];
                      options.inJustDecodeBounds = false;
                      options.inSampleSize = 2;
  
                      Bitmap thumbnail = BitmapFactory.decodeFile(extLoc
                              + fileName, options);
  
  
                      imageView.setImageBitmap(bitmap);
  
                      addBitmapToCache(url, bitmap);
  
                      pb.setVisibility(View.GONE);
  
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }
      }
  </code></pre>
  
  <p>Ok if it looks weird, I'm just hiding some names.</p>