0

我正在使用通用图像加载器在 GridView 中显示图像。图像来自数据库。我添加了一个上下文菜单来根据需要从数据库中删除图片。一切都很好。删除图片后,我需要它来刷新视图,但它仍在显示已删除的图片。(我使用了 UIL 的默认设置并且没有启用缓存)我尝试调用破坏然后初始化到图像加载器,然后调用异步任务再次查询图像但它给了我一个错误说找不到文件(已删除的文件) )。这是我的(冗长的)代码。谁能看到我错过了什么?

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();

    }
4

1 回答 1

0

尝试使用它来清空图像缓存:

Collection<String> c = ImageLoader.getInstance().getMemoryCache().keys();
for(String key : c) {
    try {
        MemoryCacheUtil.removeFromCache(key, ImageLoader.getInstance().getMemoryCache());
    } catch(Exception ex) {ex.printStackTrace();}
}
于 2013-10-07T14:36:55.093 回答