0

I am displaying images in a GridView with Universal Image Loader. The images are from a database. I added a context menu to delete pictures as needed out of the database. Everything works great up to there. After deleting the picture I need it to refresh the view but it's still displaying the deleted picture. (I used the default setup for UIL and did not enable caching) I tried to call destroy and then init to the imageloader and then called the async task to query the images again but it gives me an error saying file not found (the deleted one). Here is my (lengthy) code. Can anyone see what I am missing?

GridView gridview;
AdapterContextMenuInfo info;
ImageLoaderConfiguration config;
ImageView imageView;  
ArrayList<String> pictures = new ArrayList<String>();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ac_image_grid);

    config = new ImageLoaderConfiguration.Builder(this).build();
    imgLoader = ImageLoader.getInstance();
    imgLoader.init(config);

class getalbum extends AsyncTask<String, String, String> {

    //pre execute here  

    @Override
    protected String doInBackground(String... args) {
        int success;

        try {
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("username", restoredemail));
            params.add(new BasicNameValuePair("album_name", album_name));

            json = jsonParser.makeHttpRequest(LOGIN_URL, "POST", params);
            success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                mPictures = json.getJSONArray(TAG_POSTS);

                // looping through all posts according to the json object
                // returned

                for (int i = 0; i < mPictures.length(); i++) {
                    JSONObject c = mPictures.getJSONObject(i);

                    String dir = c.getString("dir");
                    String album = c.getString("album");
                    String pic = c.getString("photo");

                    String picture = thecompletedpicture;
                    pictures.add(picture);
                }
                return json.getString(TAG_MESSAGE);
            } else {
                Log.d("Login Failure!", json.getString(TAG_MESSAGE));
                return json.getString(TAG_MESSAGE);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }
    protected void onPostExecute(String file_url) {
        pDialog.dismiss();
        setpictures();
    }
}

private void setpictures() {
    // TODO Auto-generated method stub
    gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(new ImageAdapter(this, pictures));
    registerForContextMenu(gridview);
    gridview.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            startImagePagerActivity(position);
        }
    });
}



// and then finally the context menu makes 
// an async thread to delete the picture and 
// remove it from the database. On the 
// post execute I put the call to load the pictures again

// This is where the problem is. I need it to just display
// the remaining pictures. Maybe trying to remove the deleted 
// picture from the array and then reloading it?  I really need
// help with the code.

protected void onPostExecute(String file_url) {
        // dismiss the dialog once product deleted
        pDialog.dismiss();

        imgLoader.destroy();
        imgLoader.init(config);

        new getalbum().execute();

    }
JeffK
  • 247
  • 1
  • 5
  • 18

1 Answers1

0

Try using this to empty your image cache:

Collection<String> c = ImageLoader.getInstance().getMemoryCache().keys();
for(String key : c) {
    try {
        MemoryCacheUtil.removeFromCache(key, ImageLoader.getInstance().getMemoryCache());
    } catch(Exception ex) {ex.printStackTrace();}
}
Sherif elKhatib
  • 45,786
  • 16
  • 89
  • 106
  • Okay, that still gives me the same error E/ImageLoader(31336): java.io.FileNotFoundException: http://www.mysite/uploads/20131007_085815.jpg 10-07 09:00:18.528: E/ImageLoader(31336): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177) I also noticed it leaves a blank space where the picture was and duplicates all of the other images lol. I hate Gridview – JeffK Oct 07 '13 at 15:03