0

Universal Image Loader を使用して GridView に画像を表示しています。画像はデータベースからのものです。必要に応じてデータベースから写真を削除するためのコンテキスト メニューを追加しました。そこまではすべてうまく機能します。写真を削除した後、ビューを更新する必要がありますが、削除された写真がまだ表示されています。(UILのデフォルト設定を使用し、キャッシュを有効にしませんでした)destroyを呼び出してから、イメージローダーの初期化を試み、非同期タスクを呼び出して画像を再度クエリしましたが、ファイルが見つからないというエラーが表示されました(削除されたファイル)。これが私の(長い)コードです。誰が私が欠けているものを見ることができますか?

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